Why using AngularJS directive in comments

As you know (probably) AngularJS provides the ability to create directives based on comments (M).

But why?

What is the precedent? Any idea?

One of my students asked me and I couldn't provide any examples ... Thanks in advance!

+3


source to share


2 answers


One use case, from the Docs :

Best practice: . Comment directives were commonly used in places where the DOM API restricts the ability to create directives that span multiple elements (for example, inside elements <table>

). AngularJS 1.2 introduces ng-repeat-start

andng-repeat-end

as the best solution for this problem. Developers are encouraged to use this by special comment whenever possible.

- AngularJS Developer Guide - Directive Types



The "M" constraint is the least commonly used, typically only for backward compatibility and to pass markup validation.

+3


source


I am thinking of something like ng-if

, it puts a commented html that indicates the place where the element can be inserted, if the criteria match, maybe it has its own cases where people will use it.



+1


source







All Articles