Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
20
rated 0 times [  21] [ 1]  / answers: 1 / hits: 16211  / 11 Years ago, sun, october 27, 2013, 12:00:00

I wonder if you have an example of a directive code that reacts on angular events like $routeChangeError without injecting $rootScope in to it (to use $on in link function). It breaks in my opinion MV* pattern and produces smell-code (gives the possibility to manipulate root scope in a directive). Thanks in advance.


More From » angularjs

 Answers
22

If you are only listening for events, you don't have to use the $rootScope; do e.g. $scope.$on($routeChangeError) on the scope of the directive, from either controller or link function.



You see the $routeChangeError is broadcasted from the $rootScope, so all children receive it.


[#74697] Friday, October 25, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aleenamarinr

Total Points: 610
Total Questions: 109
Total Answers: 118

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
;