[英]How to use the URL hash in a controller with UI Router?
I need to change a scope property for every change in state (or URL hash). 我需要为状态(或URL哈希)的每次更改更改一个scope属性。 I am using
ui.router
and not ngRoute
which is a problem. 我正在使用
ui.router
而不是ngRoute
,这是一个问题。
I know $location.path()
gives me the current hash, but it does not seem to serve the purpose. 我知道
$location.path()
给了我当前的哈希值,但它似乎没有达到目的。 Below is a controller that I am using: 以下是我正在使用的控制器:
var myController = myApp.controller("myContoller",
["$scope", "$location",
function ($scope, $location) {
$scope.location = $location.path();
});
The Binding that I bind in my view with $scope.location
does not seem to be updated when a state changes. 当状态更改时,我在视图中使用
$scope.location
绑定的绑定似乎没有更新。 Is there a way I can capture a state change and probably 're-evaluate' the controller script? 有没有一种方法可以捕获状态变化并可能“重新评估”控制器脚本?
A post here: https://github.com/angular/angular.js/issues/1699#issuecomment-11496428 seems to work great for what I want. 此处的帖子: https : //github.com/angular/angular.js/issues/1699#issuecomment-11496428似乎可以很好地满足我的需求。
Basically, using a $scope.$on("$locationChangeSuccess", function (event) {});
基本上,使用
$scope.$on("$locationChangeSuccess", function (event) {});
helped. 帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.