我有角度js的服务。在这个服务中,我有一个方法,它生成一个针对json输入的get请求。
在结果上,我想对json响应进行一些处理,然后返回处理过的值。然后将处理后的值填充为选择选项。
我遇到的问题是它没有填充选择选项。
I have a plunker that has it almost working
角app.js
angular.module('my.app', []);
angular.module('my.app').controller('DemoCtrl', [ 'DemoService', function(DemoService) {
self = this;
self.chooseCountryGroups=DemoService.getCountryGroups()
}]);
角service.js
angular.module('my.app')
.factory('DemoService', ['$http', function($http) {
return {
getCountryGroups: function() {
dataResults = [];
// do some processing on json response (return only the keys)
$http.get('country-groups.json').success(function(data){
for(var countryCountryName in data){
dataResults.push(countryCountryName);
}
//console.log(dataResults); looks ok on log output
});
return dataResults;
}
}
}])
html
<html ng-app="my.app">
<body ng-controller="DemoCtrl as demoCtrl">
<select id="country" name="country" style="width: 200px" size=5
ng-model="demoCtrl.filterOptions.countryGroup"
ng-options="country as country for country in demoCtrl.chooseCountryGroup">
</select>
</body>
</html>