2

I have following code, and let you know that i am new to angularjs

<!DOCTYPE html>
<html data-ng-app="">
<head>
    <!-- <script src="scripts/angular.js"></script>-->
    <title>Angular js</title>
</head>
<body data-ng-init="names=['Ran','Run','Run']">

    <br />
    <ul>
        <li data-ng-repeat="personName in names">{{personName}}</li>
    </ul>

    <script src="scripts/angular.min.js"></script>
</body>
</html>

There is no value shown from the names in li ..... any Help or suggestion to solve the issue

2 Answers 2

3

If you open console of your browser, you can see error:

Duplicates in a repeater are not allowed. 

Use 'track by' expression to specify unique keys. Repeater: personName in ['Ran','Run','Run'], Duplicate key: string:Run

You have two same items in array (Run).

Delete last "Run" from array, and it will work fine.

Please, see: Plunker

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

1 Comment

Or add 'track by $index' to the end of the repeat expression
2

Please remove one 'Run' from your data-ng-init

And it will work fine..

<!DOCTYPE html>
<html data-ng-app="">
<head>
    <!-- <script src="scripts/angular.js"></script>-->
    <title>Angular js</title>
</head>
<body data-ng-init="names=['Ran','Run']">

    <br />
    <ul>
        <li data-ng-repeat="personName in names">{{personName}}</li>
    </ul>

    <script src="JS/angular-1.2.10.min.js"></script>
</body>
</html>

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.