Home > DeveloperSection > Forums > ng-repeat attribute not working
Takeshi Okada
Takeshi Okada

Total Post:89

Points:629
Posted on    March-19-2015 7:25 AM

 Angular JS JavaScript  Angularjs ng Repeat  Javascript Library 
Ratings:


 1 Reply(s)
 669  View(s)
Rate this:

Hi I’m new in angularjs I am try to print country list and state list. But my code is not working proper.

At the time one things is print. If you want to print country then you write print country code as first line and if you want to print state list then you write code print state list as first line according to my code.

My code is here

<h1>Sample Application</h1>

    <div ng-app="" ng-init="countries=[{locale:'en-IN',name:'India'},{locale:'en-GB',name:'United Kingdom'},{locale:'en-FR',name:'France'}]">

        <h2>List of Countries with locale:</h2>

        <ul>

            <li ng-repeat="country in countries">{{ 'Country: ' + country.name + ', Locale: ' + country.locale }}</li>

        </ul>

    </div>

 

    <div ng-app="" ng-init="states=[{language:'Hindi',name:'Uttar Pradesh'},{language:'English',name:'Banglore'},{language:'Telgu',name:'Tamil Nadu'}]">

        <ul>

            <li ng-repeat="state in states">{{'State: '+state.name+', Language: '+state.language}}</li>

        </ul>

    </div>

    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>

What is problem in my code I can’t understand please help me.

Thanks in advance.



Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    March-19-2015 7:43 AM

Your fault is you use ng-app attribute two times it is not correct way because ng-app starting point of angularjs and you know very well everything starting point is one.

So Please try this code:

<ul ng-init="countries=[{locale:'en-IN',name:'India'},{locale:'en-GB',name:'United Kingdom'},{locale:'en-FR',name:'France'}]">

            <li ng-repeat="country in countries">{{ 'Country: ' + country.name + ', Locale: ' + country.locale }}</li>

        </ul>

        <ul ng-init="states=[{language:'Hindi',name:'Uttar Pradesh'},{language:'English',name:'Banglore'},{language:'Telgu',name:'Tamil Nadu'}]">

            <li ng-repeat="state in states">{{'State: '+state.name+', Language: '+state.language}}</li>

        </ul>


Don't want to miss updates? Please click the below button!

Follow MindStick