错误:
MainCategoriesListController is not defined
仅在声明时出现,即angular.module().controller(~~,~~)
。
此外,在类别状态下,当我尝试登录result.data
时,在resolve属性中它说:
TypeError: Cannot read property 'data' of undefined
这是我的控制者:
(function () {
'use strict';
angular.module('MenuApp')
.controller('MainCategoriesListController',MainCategoriesListController);
MainCategoriesListController.$inject = ['items'];
function MainShoppingListController(items) {
var category = this;
category.items = items;
}
})();
这是状态:
(function () {
'use strict';
angular.module('MenuApp')
.config(RoutesConfig);
RoutesConfig.$inject = ['$stateProvider', '$urlRouterProvider'];
function RoutesConfig($stateProvider, $urlRouterProvider) {
// Redirect to home page if no other URL matches
$urlRouterProvider.otherwise('/');
// *** Set up UI states ***
$stateProvider
// Home page
.state('home', {
url: '/',
templateUrl: 'src/shoppinglist/templates/home.template.html'
})
// Categories list page
.state('categories', {
url: '/categories',
templateUrl: 'src/shoppinglist/templates/main-categories.template.html',
controller: 'MainCategoriesListController as category',
resolve: {
items: ['MenuDataService', function (MenuDataService) {
var promise= MenuDataService.getAllCategories();
promise.then(function (result) {
console.log("items : ",result.data);
})
}]
}
});
}
})();
这是我的服务
(function () {
'use strict';
angular.module('data')
.service('MenuDataService',MenuDataService);
MenuDataService.$inject=['$http'];
function MenuDataService($http) {
var service=this;
service.getAllCategories=function () {
var response=$http({
method: "GET",
url: "https://davids-restaurant.herokuapp.com/categories.json"
})
.then(function (result) {
console.log("Categories : ",result.data);
});
//console.log("getAllCategories data : ",response.data);
return response;
}
})();
数据是另一个模块,它被定义为MenuApp模块的依赖项。这两个模块都在不同的文件中声明。所有组件都在单独的文件中定义。
请帮助我解决该问题。