AngularJS - ng-repeat to assign/generate a new unique ID -


I'm using a simple ng-repeat to create a list of countries. Each list has a hidden row / div that can be expanded and collapsed.

The problem I am facing is that before I present Kangaroo in my application, I manually codify the element's ID manually Example: < Pre> & lt; Li data-show = "# country 1" & gt; {{Country.name}} has a population of {{country.population}} & lt; Div id = "country1" & gt; & Lt; P & gt; Expand / collapse content & lt; / Div & gt; & Lt; / li & gt; & Lt; Li data-show = "# country2" & gt; {{Country.name}} has a population of {{country.population}} & lt; Div id = "country2" & gt; & Lt; P & gt; Expand / collapse content & lt; / Div & gt; & Lt; / li & gt; & Lt; Li data-show = "# country3" & gt; {{Country.name}} has a population of {{country.population}} & lt; Div id = "country3" & gt; & Lt; P & gt; Expand / collapse content & lt; / Div & gt; & Lt; / li & gt; & Lt; Li data-show = "# country 4" & gt; {{Country.name}} has a population of {{country.population}} & lt; Div id = "country4" & gt; & Lt; P & gt; Expand / collapse content & lt; / Div & gt; & Lt; / li & gt; ng-repeat :

  & lt; li ng-repeat = "New code by using"  

Countries in countries "data-show =" ???? "{{country.name}} has a population of {{country.population}}.

& lt; p & gt; Increase / collapse content & gt; How do I specify a dynamic / incremental ID in my ng-repeat

You can $ index

  & lt; li {{country.name}} has a population of {{country.population}} & lt; div id = "country - li ng-repeat =" country in country "data-show =" ???? "& gt; {{$ Index}} "& gt; & lt; p & gt; Expand / collapse content & lt; / div & gt; & lt; / li & gt;    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -