javascript - Simple ng-repeat not working - Stack Overflow

I have following code in my angularjs app, why this simple ng-repeat is not working?var app = angular.m

I have following code in my angularjs app, why this simple ng-repeat is not working?

var app = angular.module('anApp', []);
app.controller('aCtrl', function($scope) {
  $scope.data = ["", "File", "", "Edit", "", "Format", ""];
})
<script src=".2.23/angular.min.js"></script>
<div ng-app="anApp" ng-controller="aCtrl">
  {{data}}
  <ol>
    <li ng-repet="j in data">{{j}}</li>
  </ol>
</div>

I have following code in my angularjs app, why this simple ng-repeat is not working?

var app = angular.module('anApp', []);
app.controller('aCtrl', function($scope) {
  $scope.data = ["", "File", "", "Edit", "", "Format", ""];
})
<script src="https://ajax.googleapis./ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="anApp" ng-controller="aCtrl">
  {{data}}
  <ol>
    <li ng-repet="j in data">{{j}}</li>
  </ol>
</div>

Share asked Feb 27, 2017 at 11:41 Talent RunnersTalent Runners 4195 silver badges21 bronze badges 2
  • 1 use track by $index – Hadi Commented Feb 27, 2017 at 11:42
  • The answers below are helpful, but could it just have been ng-repeat was misspelled? – TopherGopher Commented Jan 21, 2020 at 16:45
Add a ment  | 

4 Answers 4

Reset to default 2

try this. data array have duplicate item then use track by $index

<ol>
  <li ng-repeat="j in data track by $index">{{j}}</li>
</ol>

Duplicate keys are not allowed in AngularJS and also you misspelled ng-repeat

Docs

var app = angular.module('anApp', []);
app.controller('aCtrl', function($scope) {
  $scope.data = ["", "File", "", "Edit", "", "Format", ""];
})
<script src="https://ajax.googleapis./ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="anApp" ng-controller="aCtrl">
  {{data}}
  <ol>
    <li ng-repeat="j in data track by $index">{{j}}</li>
  </ol>
</div>

Angular Doc. Duplicate Key in Repeater

var app = angular.module('anApp', []);
app.controller('aCtrl', function($scope) {
  $scope.data = ["", "File", "", "Edit", "", "Format", ""];
})
<script src="https://ajax.googleapis./ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="anApp" ng-controller="aCtrl">
  {{data}}
  <ol>
<li ng-repeat="j in data track by $index">{{j}}</li>
  </ol>
</div>

You can use this code it is working
In view
    {{data}}
      <ol>
      <li ng-repeat="j in data track by $index">{{j}}</li>
      </ol>

and in Javascript

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
        $scope.data = ["", "File", "", "Edit", "", "Format", ""];
});

and for you i am writting in plunker and please correct the spelling of ng-repeat

https://plnkr.co/edit/Q1OeiIzGBgpppluvtOT1?p=preview

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744815961a4595329.html

相关推荐

  • javascript - Simple ng-repeat not working - Stack Overflow

    I have following code in my angularjs app, why this simple ng-repeat is not working?var app = angular.m

    2天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信