javascript - ng-repeat appending data multiple times -
html
<div ng-app="templeapp" ng-controller="templelist"> <div ng-repeat="temple in temples track $index" > <h2>{{temple.strtemplename}}</h2> <h4>{{temple.strtempledescription}}</h4> <h4>5km current location</h4> </div> </div>
js
var templeapp = angular.module('templeapp', []) .controller('templelist',function($scope,$http){ $scope.temples = [{"_id":"new","strtemplename":"temple 1 name","strtempledescription":"temple 1 description","strcontactnumber":"+91899999999","strtemplelocation":"chennai","itemplerating":5,"strcontactpersonname":"","strtemplecoordinates":""}] ; $http.get("https://gist.githubusercontent.com/vigneshvdm/d106ea482a792c60dff8/raw/c8f020eb54c4068e40884b8d84c972d92e8e4e08/vicky%20test%20file").success(function(data){ $scope.temples = data[0]; //uncomment line see error console.log(data[0]); }); });
problem
when comment $scope.temples = data[0];
line, ne-repeat appending data once, when assign data $scope.temples appending same data multiple time
remove track $index
in ng-repeat , change below this
in example used temple.strtemplename track filter make sure return unique names.
<div ng-app="templeapp" ng-controller="templelist"> <div ng-repeat="temple in temples track temple.strtemplename" > <h2>{{temple.strtemplename}}</h2> <h4>{{temple.strtempledescription}}</h4> <h4>5km current location</h4> </div> </div>
Comments
Post a Comment