I've been attempting to implement this specific approach in my application, but I'm encountering difficulties.
CountriesModel.js
app.service('CountriesModel', ['$http',
function($http) {
$http.get(baseUrl + 'api/countries').success(function(data) {
this.countries = data;
});
}]);
UserCtrl.js
app.controller('UserCtrl', ['$scope', 'CountriesModel',
function($scope, CountriesModel) {
$scope.CountriesModel = CountriesModel;
}]);
user.html
<select ng-options="country.iso2 as country.short_name for country in CountriesModel.countries" ng-model="selectedCountry"></select>
Despite seeing that countries
inside CountriesModel
are retrieved properly in the AngularJs inspector plugin, I'm still encountering an issue where $scope.CountriesModel
inside UserCtrl
remains undefined
and the select
element remains empty...