Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Something along the lines of: link: function($scope, element, attrs, $location) {

Is this possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
916 views
Welcome To Ask or Share your Answers For Others

1 Answer

In the declaration of the directive, inject the location service.

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());
  }
 };
}]);

If you are attempting to get the current location, use location.path() or, alternatively, use the $route service.

Information on both:

  1. $route Docs
  2. $location Docs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...