hussain hussain - 5 months ago 15
Javascript Question

ng-repeat is not binding values into Dom?

I am loading data dynamically to ng-repeat so once i receive data its not binding it to

ul
, i know sometime it happens if you have duplicate indexes but in below case i am not sure what is happening, Any idea ?

main.html

<div>
<ul ng-repeat="message in data track by index">
<li>{{message}}</li>
</ul>
</div>


ctrl.js

angular.module('loggingApp').controller('DitCtrl',function ($scope,DitFactory) {
'use strict';
DitFactory.getLogs().then(function (response) {
$scope.data = response.data;
console.log($scope.data);
});
});


console.log

printing data in console

["test.txt", "test1.txt", "test2.txt", "test3.txt", "test4.txt"]

Answer

Your ng-repeat needs to look like this:

ng-repeat="message in data track by $index"