Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json Angularjs服务,用于通过处理填充get请求中的选项_Json_Angularjs_Populate_Get Request - Fatal编程技术网

Json Angularjs服务,用于通过处理填充get请求中的选项

Json Angularjs服务,用于通过处理填充get请求中的选项,json,angularjs,populate,get-request,Json,Angularjs,Populate,Get Request,我有一个服务。在这个服务中,我有一个方法可以根据json输入生成get请求 对于结果,我想对json响应进行一些处理,然后返回处理后的值。处理后的值将作为选择选项填充 我遇到的问题是它没有填充选择选项 angular app.js angular.module('my.app', []); angular.module('my.app').controller('DemoCtrl', [ 'DemoService', function(DemoService) { self = thi

我有一个服务。在这个服务中,我有一个方法可以根据json输入生成get请求

对于结果,我想对json响应进行一些处理,然后返回处理后的值。处理后的值将作为选择选项填充

我遇到的问题是它没有填充选择选项

angular app.js

angular.module('my.app', []);

angular.module('my.app').controller('DemoCtrl', [ 'DemoService', function(DemoService) {

  self = this;  
  self.chooseCountryGroups=DemoService.getCountryGroups()

}]);
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;
              }        
          }
  }])
角度服务.js

angular.module('my.app', []);

angular.module('my.app').controller('DemoCtrl', [ 'DemoService', function(DemoService) {

  self = this;  
  self.chooseCountryGroups=DemoService.getCountryGroups()

}]);
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>


在您最后一次发表评论后,问题到底是什么?谢谢您-您是如何解决的。。我正在查看代码,似乎看不到它?找到它我错过了键入的
demoCtrl。选择CountryGroup
当它应该是
demoCtrl时。选择CountryGroups
请留下答案并标记它已解决,以便将来帮助他人。