无法在我的 angularjs 控制器中访问 $routeParams
can't access $routeParams in my angularjs controller
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
变量。错误显示无法访问 energyID
您正在使用 Angular 的 'minifiyable' 语法但未提供 $routeParams
作为参数之一。这一行:
myApp.controller('detailsController', ['$scope', function ($scope,$routeParams) {
应该是:
myApp.controller('detailsController', ['$scope', '$routeParams', function ($scope,$routeParams) {
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
变量。错误显示无法访问 energyID
您正在使用 Angular 的 'minifiyable' 语法但未提供 $routeParams
作为参数之一。这一行:
myApp.controller('detailsController', ['$scope', function ($scope,$routeParams) {
应该是:
myApp.controller('detailsController', ['$scope', '$routeParams', function ($scope,$routeParams) {