Dynamically add directives in AngularJS (while ditching jQuery)
Let’s say you want to add a button that adds more buttons (or any other interactive element) that do something when you click them.
There is a few ways to achieve this, but most of the solutions I found either didn't work (probably due to using an older AngularJS version), seemed unnecessarily complicated or relied on using jQuery.
Here is what I came up with (tested with Angular 1.2.9).
To see a working example with the full code, visit this page: http://jsfiddle.net/ftfish/KyEr3/
For a walkthrough, see my blog post.
Written by Stefan Bohacek
Related protips
1 Response
Here's a super easy article on 'Dynamically Compile and Add a custom directive in AngularJs' with snapshots. http://www.learn-angularjs-apps-projects.com/AngularJs/dynamically-add-directives-in-angularjs
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Angularjs
Authors
Related Tags
#angularjs
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#