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
Post a Comment