文件结构:
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
});
}());
agencyResource.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' },
});
}
}());
agencyListCtrl.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);
})
}
}());
ERROR:
HTML1300:导航已发生。 index.html错误:[$ injector:unpr] 未知提供者:agencyResourceProvider< - agencyResource< - AgencyListCtrl http://errors.angularjs.org/1.5.9/ $注射器/ unpr?P0 = agencyResourceProvider%20%3 C-%20agencyResource%20%3 C-%20AgencyListCtrl 在匿名函数(http://localhost:61924/Scripts/angular.js:4554:13) at getService(http://localhost:61924/Scripts/angular.js:4707:11) 在匿名函数(http://localhost:61924/Scripts/angular.js:4559:13) at getService(http://localhost:61924/Scripts/angular.js:4707:11) at injectionArgs(http://localhost:61924/Scripts/angular.js:4731:9) 在实例化(http://localhost:61924/Scripts/angular.js:4774:7) at $ 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)
我不确定天气我在这里注入了一切吗?任何帮助,将不胜感激。这是我的第一个有角度的应用程序,所以我有点绿。 Stack Overflow告诉我我必须输入更多细节,但代码帖子非常自我解释。我
答案 0 :(得分:0)
答案是我在agencyResource.js文件中声明了ngResource。它看起来应该是这样的。我的坏。
agencyResource.js
cv2.pyd