javascript - $route.current.pathParams 和 $routeParams 的区别

标签 javascript angularjs

我试图在不刷新我的页面的情况下更新一个 url,我正在使用这个解决方案:https://github.com/angular/angular.js/issues/1699#issuecomment-45048054

我注意到这段代码有效:

$route.current.pathParams.program = "someValue";
$location.path('/myapp/' + $routeParams.program);

但是这段代码不起作用:

$routeParams.program = "someValue";
$location.path('/myapp/' + $routeParams.program);

我想知道有什么区别,为什么一个有效而另一个无效?

最佳答案

它不起作用,因为 AngularJS 无法识别对 $routeParams 的任何更改,直到路由更改后,根据 documentation

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 - $route.current.pathParams 和 $routeParams 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30762661/

相关文章:

javascript - 将函数附加到左键单击 <listbox> 项目

javascript - Ajax从restful API获取未定义的列表

javascript - AngularJS错误: Provider must return value from $get factory method

javascript - 实现 Angular ui-router 而不是 ng-router

javascript - 在 Udemy Wordpress 讲座之后 - Live Search Bar 破坏了我的代码

javascript - 在索引页面中包含 angularjs 的优先顺序?

javascript - JavaScript 函数之间的 OR 运算符

javascript - 将 "active"类应用到移动设备上的选项卡,而不是桌面设备

Javascript 对象设置了一个属性,该属性是返回 promise 的函数调用

javascript - 如何从地址栏中删除网络摄像头图标