var myApp = angular.module('myApp', ['ngGrid', 'ngRoute']);
myApp.config(['$routeProvider', function ($routeProvider)
{
$routeProvider.
when('/:energyId/:energyChain/:resourceId/:facilityId',
{
templateUrl: '/Content/resourceTemplate.html',
controller: 'detailsController'
}).
otherwise({
redirectTo: '/param1/param1/param1/param1'
});
}]);
myApp.controller('detailsController', ['$scope', function ($scope,$routeParams) {
//here the error when i add the following single statement
$scope.status = $routeParams.energyID;//This cuases angular to fail but only this controller
$scope.models = [
{ Parameter: "Bob", Period: 25, Values: "NewYork", Scale: "NewYork", Unit: "NewYork", Per: "NewYork" },
{ Parameter: "Bob", Period: 25, Values: "NewYork", Scale: "NewYork", Unit: "NewYork", Per: "NewYork" },
{ Parameter: "Bob", Period: 25, Values: "NewYork", Scale: "NewYork", Unit: "NewYork", Per: "NewYork" },
{ Parameter: "Bob", Period: 25, Values: "NewYork", Scale: "NewYork", Unit: "NewYork", Per: "NewYork" },
{ Parameter: "Bob", Period: 25, Values: "NewYork", Scale: "NewYork", Unit: "NewYork", Per: "NewYork" }
];
}]);
我已经测试了我的代码,直到我在访问status
的控制器中添加了$routeParams
变量。错误显示无法访问energyID
答案 0 :(得分:1)
您正在使用Angular的'minifiyable'语法,但不提供$routeParams
作为参数之一。这一行:
myApp.controller('detailsController', ['$scope', function ($scope,$routeParams) {
应该是:
myApp.controller('detailsController', ['$scope', '$routeParams', function ($scope,$routeParams) {