Issue
I'm using angularJS 1.3 in my app, and according to best practices of using angular, instead of $scope
we use var self = this
. Is it possible using $on
/ $emit
without injecting $scope
/ rootScope
?
Solution
as David L answer in this question
In order to use anything that exists on $scope, you are forced to inject $scope. It's unfortunately that straightforward, which is a shortcoming of the "as" syntax.
The good news however is that injecting $scope alongside this does not change how the controller as syntax functions, it simply gives you access to all of the event management that lives on $scope.
It's worth noting that this is one of the primary reasons for what is coming in Angular 2.0...there is a real problem and discrepancy between $scope and the "Controller as" syntax that was bolted on to solve scoping issues in views.
Answered By - Elad Hirsch
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.