angular.element

Share this video with your friends

Send Tweet

A brief overview of using element in an AngularJS directive, and how to target one without jquery, and also how to use replace and compile function

Nicholas Westby
Nicholas Westby
~ 11 years ago

How are you typing into a second window and having that markup be injected into a string into your first window in WebStorm? Looks really nifty.

Roman Ganchenko
Roman Ganchenko
~ 11 years ago

Alt-tab > Edit HTML fragment

Karen
Karen
~ 10 years ago

I don't get the 'this.link' 'return link' logic. Why do we assign link like this.link but then refer to it in compile section like just 'link'?

John Lindquist
John Lindquist(instructor)
~ 10 years ago

I updated the code to show the proper "var link" approach (I had this corrected with an overlay on YouTube, but missed it in migrating the videos).

This approach is simply a convenience, nothing more. You can leave the link function as an anonymous function "link: function(){...}" if you'd like. The only tricky part is that a compile function returns a link function, so using compile (which is an edge case) will look much different than the standard way of just using "link: function()" on a directive definition object".

Amit
Amit
~ 10 years ago

You were probably just demoing features but this approach should not be used in actual app as directive function is not executed repeatedly. And having multiple instances of directive breaks this example. Am I correct?