是否有可能获得在角JS指令当前位置$? [英] Is it possible to get the current $location in a directive in Angular JS?
本文介绍了是否有可能获得在角JS指令当前位置$?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
线沿线的东西:链接:功能($范围,元素,ATTRS,$位置){
这可能吗?
推荐答案
在该指令的声明,注入的位置服务。
In the declaration of the directive, inject the location service.
app.directive('myDirective', ['$location', function(location){
return {
link: function(scope, elem, attrs){
//things happen here
location.url('/');
}
};
}]);
如果您正试图获取当前位置,使用location.path(),或者,使用$的航线。两个信息:
If you are attempting to get the current location, use location.path() or, alternatively, use the $route service. Information on both:
- http://docs.angularjs.org/api/ngRoute.$route
- http://docs.angularjs.org/api/ng.$location
这篇关于是否有可能获得在角JS指令当前位置$?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文