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

demo link

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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -