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
Javascript 关于url散列更改成功-在Angular指令中_Javascript_Angularjs_State_Directive - Fatal编程技术网

Javascript 关于url散列更改成功-在Angular指令中

Javascript 关于url散列更改成功-在Angular指令中,javascript,angularjs,state,directive,Javascript,Angularjs,State,Directive,我正在使用的应用程序正在使用状态和ui-sref进行路由(还有剑道,但我不知道它是否会影响路由)。我在html上有5个选项卡(相同的状态-只是#tab-x从#tab-1更改为#tab-5)。我将指令绑定到每个选项卡,在指令中,我使用$location服务确定当前url。问题是:当我 console.log($location)事件在那里,但前缀为$sign: $scope.$on("$locationChangeSuccess", function (event, next, current)

我正在使用的应用程序正在使用
状态
ui-sref
进行路由(还有剑道,但我不知道它是否会影响路由)。我在
html
上有5个选项卡(相同的状态-只是
#tab-x
#tab-1
更改为
#tab-5
)。我将指令绑定到每个选项卡,在指令中,我使用
$location
服务确定当前url。问题是:当我


console.log($location)
事件在那里,但前缀为$sign:

$scope.$on("$locationChangeSuccess", function (event, next, current) {
    console.log($location.hash());
}); 
您可以使用
$location.hash()
获取值

在这里工作:

$location#事件-$locationChangeSuccess

这是angularjs事件。您也可以使用ui路由器的
$stateChangeSuccess
事件,正如@Satpal在注释中所指出的,但该事件可能不会被调用,因为状态实际上没有改变(您没有定义包含哈希的状态,对吗?)


另外,您不应该使用前缀属性,这些属性是私有的

事件在那里,但前缀为$sign:

$scope.$on("$locationChangeSuccess", function (event, next, current) {
    console.log($location.hash());
}); 
您可以使用
$location.hash()
获取值

在这里工作:

$location#事件-$locationChangeSuccess

这是angularjs事件。您也可以使用ui路由器的
$stateChangeSuccess
事件,正如@Satpal在注释中所指出的,但该事件可能不会被调用,因为状态实际上没有改变(您没有定义包含哈希的状态,对吗?)


另外,您不应该使用前缀属性,这些属性是私有的

如果你仔细看我的问题,你可以看到“相同状态”,所以这个事件不会触发。如果你仔细看我的问题,你可以看到“相同状态”,所以这个事件不会触发。我只是忘记写$sign,因为某种原因它不会触发。也不触发stateChangeSuccess(正如我所说的,状态在散列更改后保持不变)。当url散列更改时,
$locationChangeSuccess
应该触发(在一个项目中的某个地方测试)<代码>$stateChangeSucture可能没有启动,因为状态确实没有更改…你确定没有输入错误吗?我用它创建了plunker,它工作正常,因此如果有问题,它位于代码中的其他地方…我只是忘了写$sign,因为某些原因它没有启动。也不触发stateChangeSuccess(正如我所说的,状态在散列更改后保持不变)。当url散列更改时,
$locationChangeSuccess
应该触发(在一个项目中的某个地方测试)<代码>$stateChangeSucture可能没有触发,因为状态确实没有更改…您确定没有输入错误吗?我用它创建了plunker,它工作正常,因此如果有问题,它位于代码的其他地方。。。