r/angularjs • u/abyx • Sep 07 '16
Dissecting a favorite interview question: How would you implement ng-click
http://www.codelord.net/2016/09/06/angular-interview-question-deep-dive-implement-ng-click/
53
Upvotes
1
u/_Aardvark Sep 08 '16
On an somewhat related note, anyone ever look at the angular code where they define all the ng-eventhandler directives. Where they iterate over an array of event names to define each directive with the same code.
Not groundbreaking, I just thought it was clever.
1
2
1
Sep 08 '16
great example. thanks
and I think ng-click somehow commonly used when it comes to submit/triggering something thinggie
1
u/10gistic Sep 08 '16
Depending on your use case, $eval is probably better yet. You don't know when the expression might change (say, swapping out functions of the same name on the $scope), and $parse is only going to evaluate once, rather than every click event.
Some efficiency trade-off obviously applies here, but it's probably the least likely to surprise your users (or yourself) with its behavior.