我认为我的问题是访问它,代码工作正常,直到该行尝试了$ routeParams的日志并返回如图所示,但无法使用特定属性的点访问它
var myApp = angular.module('myApp', ['ngGrid', 'ngRoute', "ngAnimate", "ngAria", 'ngMaterial']);
var statusLabel;
var selectedItem;
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', '$routeParams', function ($scope, $routeParams) {
//After testing the following code returns {"energyId":"param1","energyChain":"param1","resourceId":"param1","facilityId":"param1"} for matching url
//but when i try to access it like $routeParams.energyId it say Undefined the problems seems accessing the returned value
$scope.statusLabel = $routeParams;
//this is the error
$scope.label = $routeParams.energyId;
**错误是访问routeparams **
中的详细信息答案 0 :(得分:1)
来自angular documentation for $ routeProvider
请注意,ngRoute。$ routeParams仍然会引用前一个 这些解析函数中的路由。使用$ route.current.params来 相反,访问新的路线参数。
所以..
$scope.label = $route.current.params.energyId;