2

I have a code and I want to loop throught the array in json format by using ng-repeat and ng-init.

But the code isn't working.

Below is the following code.


<!DOCTYPE html>
<html ng-app="">
<head>
    <title></title>
</head>
<body>
    <h1>
        ng - repeat
    </h1>
    <hr />
    <div ng-init="myFavLan=[{name:'PHP',extension:'.php'},
                            {name:'Javascript',extension:'.js'},
                            {name:'HTML',extension:'.html'}
                           ]">
        <p ng-repeat="language in myFavlan">
            Name : {{ language.name }} <br />
            Extension : {{ language.extension }}
        </p>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</body>
</html>

Please note that I am a beginner in angularjs

2 Answers 2

3

Javascript is case-sensitive, so the variable myFavlan you have in the ng-repeat is undefined. Just change

<p ng-repeat="language in myFavlan">

to

<p ng-repeat="language in myFavLan">

You could also change your ng-init variable.

Sign up to request clarification or add additional context in comments.

Comments

2

It should be myFavLan Change

From

<p ng-repeat="language in myFavlan">

To

<p ng-repeat="language in myFavLan">

DEMO

<!DOCTYPE html>
<html ng-app="">
<head>
    <title></title>
</head>
<body>
    <h1>
        ng - repeat
    </h1>
    <hr />
    <div ng-init="myFavLan=[{name:'PHP',extension:'.php'},
                            {name:'Javascript',extension:'.js'},
                            {name:'HTML',extension:'.html'}
                           ]">
        <p ng-repeat="language in myFavLan">
            Name : {{ language.name }} <br />
            Extension : {{ language.extension }}
        </p>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</body>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.