在上面的代码中,第一个 console.log 返回未定义
但第二个返回一个已设置 cpf 属性的对象。为什么?
我的网址:http://xxxxxxx/#!/cpf/68473303253
我的模块
angular.module('welcomeback').controller('welcomeback', ['$scope', '$location', '$routeParams', function($scope, $location, $routeParams){
console.log('First console log');
console.log($routeParams.cpf);
console.log('Second console log');
console.log($routeParams);
最佳答案
因为当 Controller 加载并打印第一个控制台时,路由更改仍在进行中。
来自 Angular :
Note that the $routeParams are only updated after a route change completes successfully. This means that you cannot rely on $routeParams being correct in route resolve functions. Instead you can use $route.current.params to access the new route's parameters.
关于javascript - $routeParams 中的参数未定义,但 $routeParams 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41896810/