gpt4 book ai didi

javascript - $routeParams 中的参数未定义,但 $routeParams 未定义

转载 作者:行者123 更新时间:2023-12-03 05:09:08 26 4
gpt4 key购买 nike

在上面的代码中,第一个 console.log 返回未定义

但第二个返回一个已设置 cpf 属性的对象。为什么?

我的网址:http://xxxxxxx/#!/cp​​f/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);

$routeParams

骗子:https://plnkr.co/edit/Exbherhe6TNYb9t5ThfL

最佳答案

因为当 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com