Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ng-repeat vs data-ng-repeat [duplicate]

Tags:

angularjs

Is there any difference between ng-repeat or data-ng-repeat in Angularjs?

I believe there are other directives with data prefix as well.

Thanks

like image 437
Nexus23 Avatar asked Dec 31 '13 20:12

Nexus23


People also ask

What is data ng-repeat?

The data-ng-repeat allows the HTML to be validated through validators that do not understand Angular. The documentation is here with directives. This is from the docs: Angular normalizes an element's tag and attribute name to determine which elements match which directives.

How do you prevent duplicates in NG-repeat?

You can use unique filter while using ng-repeat . If you use track by $index then unique won't work.

What can I use instead of NG-repeat?

You can consider using transclusion inside a custom directive, to achieve the behavior you are looking for without using ng-repeat.

Why we use NG-repeat in angular?

AngularJS ng-repeat Directive The ng-repeat directive repeats a set of HTML, a given number of times. The set of HTML will be repeated once per item in a collection. The collection must be an array or an object. Note: Each instance of the repetition is given its own scope, which consist of the current item.


1 Answers

They are aliases. Angular allows both in order to name a directive. The data-ng-repeat allows the HTML to be validated through validators that do not understand Angular.

The documentation is here with directives.

This is from the docs:

Angular normalizes an element's tag and attribute name to determine which elements match which directives. We typically refer to directives by their case-sensitive camelCase normalized name (e.g. ngModel). However, since HTML is case-insensitive, we refer to directives in the DOM by lower-case forms, typically using dash-delimited attributes on DOM elements (e.g. ng-model).

And all these are valid:

  <span ng-bind="name"></span> <br/>   <span ng:bind="name"></span> <br/>   <span ng_bind="name"></span> <br/>   <span data-ng-bind="name"></span> <br/>   <span x-ng-bind="name"></span> <br/> 

AFAIK, you can use these naming conventions in any directive that Angular parses.

like image 139
Davin Tryon Avatar answered Nov 01 '22 04:11

Davin Tryon