沿着线的东西:link: function($scope, element, attrs, $location) {
这可能吗?
在指令的声明,注入的位置服务。
app.directive('myDirective', ['$location', function($location) {
return {
link: function(scope, elem, attrs) {
// path() and url() can be used as getters or setters
console.log($location.url());
console.log($location.path());
}
};
}]);
如果您正在试图将当前位置,使用location.path()
,或者使用$route
服务。
两个信息:
以为注射服务为条指令,它仍然得到未定义为链接功能,对于需要使用
location.hash = "#/path_name";
在链接功能,将工作