Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.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
Javascript angular.js:13294错误:[$injector:unpr]未知提供程序:cityResourceProvider<;-城市资源<;-cityListCtrl_Javascript_Angularjs - Fatal编程技术网

Javascript angular.js:13294错误:[$injector:unpr]未知提供程序:cityResourceProvider<;-城市资源<;-cityListCtrl

Javascript angular.js:13294错误:[$injector:unpr]未知提供程序:cityResourceProvider<;-城市资源<;-cityListCtrl,javascript,angularjs,Javascript,Angularjs,我第一次与angularJS合作,并与服务和工厂合作创建web api REST调用。我现在在打电话之前就收到了这个错误: angular.js:13294 Error: [$injector:unpr] Unknown provider: cityResourceProvider <- cityResource <- cityListCtrl common.services.js (function() { "use strict"; angular.modul

我第一次与angularJS合作,并与服务和工厂合作创建web api REST调用。我现在在打电话之前就收到了这个错误:

angular.js:13294 Error: [$injector:unpr] Unknown provider: cityResourceProvider <- cityResource <- cityListCtrl
common.services.js

(function() {
    "use strict";

    angular.module("common.services", ["ngResource", "ngRoute"])
        .constant("appSettings", {
            serverPath: "http://localhost:49828/"
        });
});
cityResource.js

(function() {
    "use strict";

    function cityResource($resource, appSettings) {
        return $resource(appSettings.serverPath + "api/City");
    }

    angular
        .module("common.services", [])
        .factory("cityResource",
        [
            "$resource",
            "appSettings",
            cityResource
        ]);
}());
cityListCtrl.js(控制器)

html



提前谢谢

您没有调用
common.services.js
,因为它的iLife函数应该自己得到调用

(function() {
    "use strict";

    angular.module("common.services", ["ngResource", "ngRoute"])
        .constant("appSettings", {
            serverPath: "http://localhost:49828/"
        });
})();
这解决了我的问题:

(function() {
    "use strict";

   var app = angular.module("politicalHub",["common.services"]);

}());

我在common.services.js中做了这个更改,但仍然得到相同的错误
 <form>
              <div ng-controller="cityListCtrl as vm" align="center">
                  <div class="col-lg-12" style="padding: 0">
                      <select ng-options="city.city_name for city in cities" ng-model="city.name" class="form-control">

                      </select>
                  </div>
              </div>
          </form>
(function() {
    "use strict";

    angular.module("common.services", ["ngResource", "ngRoute"])
        .constant("appSettings", {
            serverPath: "http://localhost:49828/"
        });
})();
(function() {
    "use strict";

   var app = angular.module("politicalHub",["common.services"]);

}());