Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS使用$route更改路线_Angularjs - Fatal编程技术网

AngularJS使用$route更改路线

AngularJS使用$route更改路线,angularjs,Angularjs,我正在使用$routeChangeStart as实现身份验证检查,并寻找一种方法来保存next对象中提供的所有详细信息。AngularJS显示您可以设置$route.current,我希望我可以执行以下操作来更改$route,而不是使用$location: $route.current = { templateUrl: 'detail.html', controller: 'MainCtrl' }; $route.reload(); 我知道$route.current可以更新,因为设置后,c

我正在使用$routeChangeStart as实现身份验证检查,并寻找一种方法来保存
next
对象中提供的所有详细信息。AngularJS显示您可以设置
$route.current
,我希望我可以执行以下操作来更改
$route
,而不是使用
$location

$route.current = { templateUrl: 'detail.html', controller: 'MainCtrl' };
$route.reload();
我知道$route.current可以更新,因为设置后,
console.log
会显示它确实收到了更改:

console.log("current route: ", $route.current.templateUrl );
不幸的是,它不起作用。我正在创建的应用程序具有使用
$routeProvider
定义的附加参数,我希望保留这些参数

有什么想法吗


这里是一个I设置来说明这一点。

I当然可能是错误的,但我认为您无法使用
$route
$route.current
是只读的)。如果需要在多个控制器上保存状态,请考虑使用内存数据、cookie、本地存储等可能支持的服务。保存其值,然后您可以登录并最终将位置设置为存储的value@BrandonTilley这就是问题所在,$route.current不是只读的。如果添加
console.log(“当前路由:,$route.current.templateUrl”)设置后,您将看到它已被更新。@Anton遗憾的是$location没有帮助,因为我将其他参数设置为路由的一部分。例如,我有一个名为“auth”的参数,希望可以使用代码打开和关闭它。当然,我还有其他方法可以做到这一点,但这个问题实际上是关于我可以用$route做什么。答案可能很简单,就像布兰登说的:不,你不能。对不起,只读,我的意思是你只能读它。该值仅供您检查,不可更改。作为浏览器中的JavaScript,它不是真正的只读。