NG-REPEAT ATTRIBUTE NOT WORKING

Takeshi Okada

Total Post:89

Points:629
Posted by  Takeshi Okada
 1136  View(s)
Ratings:
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.

  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: ng-repeat attribute not working

    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>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!