类似于以下内容: link: function($scope, element, attrs, $location) {
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.path()
$route
两者的信息: