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
4 Answers
Reset to default 2try 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
评论列表(0条)