无法使用点 (.) 访问返回的正确返回的 $routeParams
can't access the returned correctly returned $routeParams using a dot (.)
我认为我的问题是访问它代码工作正常,直到该行尝试 $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;
**访问路由参数中的详细信息时出错**
来自 angular documentation 的 $routeProvider
Be aware that ngRoute.$routeParams will still refer to the previous
route within these resolve functions. Use $route.current.params to
access the new route parameters, instead.
所以..
$scope.label = $route.current.params.energyId;
Referred from
我认为我的问题是访问它代码工作正常,直到该行尝试 $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;
**访问路由参数中的详细信息时出错**
来自 angular documentation 的 $routeProvider
Be aware that ngRoute.$routeParams will still refer to the previous route within these resolve functions. Use $route.current.params to access the new route parameters, instead.
所以..
$scope.label = $route.current.params.energyId;
Referred from