So in AngularJS do you choose “A” or “E”? Attribute or element in a directive? Let’s have a look.
Element Example.
1 2 3 |
<navbar></navbar> |
Attribute Example.
1 2 3 |
<div navbar></div> |
Attribute Example 2
1 2 3 |
<input datepicker></input> |
So which one do you choose? and more importantly, why?
- Element essentially means creating a custom HTML element which can be used like a new HTML tag.
- Attribute basically means using a div (or such) and adding the element as an attribute to that already established HTML tag.
- Older browsers (inc IE) can’t handle custom directives as elements https://docs.angularjs.org/guide/ie
What about “C” and “M”?
There is also “C” which is Class.
1 2 3 |
<div class=”rating”> |
And “M” which is Comment
1 2 3 |
<!– directive: rating –> |
refs:
- https://www.befundoo.com/university/tutorials/angularjs-directives-tutorial/
- https://docs.angularjs.org/guide/ie