jquery - element vs. this in AngularJS Directives -


once jquery included in angular, inside directives 1 free use both $(element) , $(this) dom manipulations.

what difference between them? 1 recommended on other? interchangeable?

$(this) depend on context of method being executed, $(element) refer the directive attached to.

here's contrived example

module.directive('mydirective', [function() {     return {         template: '<div><button id="btn">click me</button></div>',         restrict: 'e',         link: function(scope, element, attrs, controller) {                 $("#btn").on('click', function() {                     // $(this) != $(element)                     // $(this) button element template                     // $(element) directive element                 });             }         } }]); 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -