【发布时间】:2017-04-25 08:49:53
【问题描述】:
文件结构:
app.js
(function () {
"use strict";
var app = angular.module("app", ["common.services", "ngRoute", "ngResource"])
app.config(function ($routeProvider) {
$routeProvider
// route for the home page
//.when('/', {
// controller: 'mainController',
// templateUrl: 'app/linkPages/home.html'
//})
// route for the about page
//.when('/about', {
// controller: 'aboutController',
// templateUrl: 'app/linkPages/about.html'
//})
// route for the contact page
//.when('/contact', {
// controller: 'contactController',
// templateUrl: 'app/linkPages/contact.html'
//})
.when('/', {
controller: 'AgencyListCtrl',
templateUrl: 'app/agencies/agencyListView.html'
})
//.when('/agencyEditView', {
// controller: 'AgencyEditCtrl',
// templateUrl: 'app/agencies/agencyEditView.html'
//});
});
// create the controller and inject Angular's $scope
app.controller('mainController', function ($scope) {
// create a message to display in our view
$scope.message = 'This is the Main controller page';
});
app.controller('aboutController', function ($scope) {
$scope.message = 'This is the about controller page';
});
app.controller('contactController', function ($scope) {
$scope.message = 'This is the contact controller page';
});
}());
common.services.js
(function () {
"use strict";
angular
.module("common.services",
["ngResource"])//common.services
.constant("appSettings",
{
serverPath: "http://localhost:53403/" // will replace production server url
});
}());
代理资源.js
(function () {
"use strict";
angular.module("app")//common.services
.factory("agencyResource"
["ngResource", "$resource",
"appSettings",
agencyResource])
function agencyResource($resource, appSettings) {
return $resource(appSettings.serverPath + "/api/v1/agencies/:id", null,
{
'update': { method: 'PUT' },
});
}
}());
代理列表Ctrl.js
(function () {
"use strict";
angular
.module("app")
.controller("AgencyListCtrl",
["agencyResource",
AgencyListCtrl]);
function AgencyListCtrl(agencyResource) {
var vm = this;
//agencyResource.query({ $filter: "contains(Abbr,'IOT')" },
// function (data) {
// vm.agencies = data;
// console.log(result);
//})
agencyResource.query({},
function (data) {
vm.agencies = data;
console.log(result);
})
}
}());
错误:
HTML1300:发生导航。 index.html 错误:[$injector:unpr] 未知提供者:agentResourceProvider http://errors.angularjs.org/1.5.9/$injector/unpr?p0=agencyResourceProvider%20%3C-%20agencyResource%20%3C-%20AgencyListCtrl 在匿名函数 (http://localhost:61924/Scripts/angular.js:4554:13) 在 getService (http://localhost:61924/Scripts/angular.js:4707:11) 在匿名函数 (http://localhost:61924/Scripts/angular.js:4559:13) 在 getService (http://localhost:61924/Scripts/angular.js:4707:11) 在 injectionArgs (http://localhost:61924/Scripts/angular.js:4731:9) 在实例化 (http://localhost:61924/Scripts/angular.js:4774:7) 在 $controller (http://localhost:61924/Scripts/angular.js:10533:7) 在链接 (http://localhost:61924/Scripts/angular-route.js:1056:9) 在匿名函数 (http://localhost:61924/Scripts/angular.js:1258:11) 在 invokeLinkFn (http://localhost:61924/Scripts/angular.js:10095:9)
我不确定我在这里注入了所有东西的天气?任何帮助,将不胜感激。这是我的第一个 Angular 应用程序,所以我有点绿。 Stack Overflow 告诉我必须输入更多详细信息,但代码帖子非常不言自明。我
【问题讨论】:
-
如果您在agentListCtrl.js之前导入agentResource.js,请检查index.html
-
我对你的代理资源资源声明有点好奇。您正在注入“ngResource”、“$resource”、“appSettings”,但您的参数是“agencyResource($resource, appSettings)”。可能是个问题。
标签: javascript