0
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" }
];
}]);
我已經測試我的代碼和它的工作,直到我在訪問$routeParams
控制器增加了status
變量$ routeParams。錯誤顯示無法訪問energyID
不能訪問我的angularjs控制器
效果很好,感謝男人@sdgluck –