在angularjs中的ng-repeat中重复ng-repeat

时间:2016-11-30 03:55:48

标签: angularjs

我是



routerApp.controller('HomePageCtrl',['$scope','$rootScope','searchFood','$timeout','$cookies',function($scope,$rootScope,searchFood,$timeout,$cookies){
  
   var a=[];
   $scope.fooditems= {};
   
   
   
  $scope.Fn_LoadTimeslotWise = function(ts){
	$scope.tsfooditems = {};
   
	var longitude = $cookies.longitude;
	var latitude = $cookies.latitude;
	var sdate = $cookies.date;
	var timeslot1 = ts;
    var timeslot2 = timeslot1.substr(0,5);
    var timeslot3 = timeslot1.substr(9,2);
    var timeslot4 = timeslot2 + timeslot4;
    
    var timeslot5 = timeslot1.substr(14,5);
    var timeslot6 = timeslot1.substr(23,2);
    var timeslot7 = timeslot5 + timeslot6;
    
    var timefrom = sdate +" "+ timeslot2;
    var timeto = sdate +" "+ timeslot5;
   // console.log(timefrom);
   //console.log(timeto);
   $scope.tim = '.' + ts;
    $timeout(function(){
		
	searchFood.ChangeTimeSlot(latitude,longitude,sdate,timefrom,timeto).then(function(d){
	$scope.tsfooditems ={};
	$scope.tsfooditems = d[0];
	
	});
   
     });
  }
}]);

  <div ng-repeat = "timeslot in timeslots">
      <h1 class="title"> {{ timeslot.date_time }} </h1>
      <div class="row product-list-wrap" ng-init = "Fn_LoadTimeslotWise(timeslot.date_time)">
          <h2 ng-show="showsearchmsg" ng-bind="searchresult"></h2>
        <div class="col-md-4" ng-repeat="tsfooditem in tsfooditems ">
          <div class="product-box view view-third">
            <div class="product_img">  <span class="favourite"> <i class="fa fa-heart"> </i> </span>
             <span class="veg"> <img src="images/veg.png"></span><a href="#" data-toggle="modal" data-target="#chefdetails"  id=""><img ng-src="{{tsfooditem.picture}}" width="200px" height="150px" ng-click="Fn_fooddetails(tsfooditem.menu_id)"> </a></div>
            <div class="product-content">
              <div class="product-title">
                <h2 ng-bind="tsfooditem.menu_name | uppercase"></h2>
                <h3 ng-bind="tsfooditem.chef_name"></h3>
              </div>
              <div class="product-rate"><b ng-bind="currency"></b>.&nbsp;<span ng-bind="tsfooditem.cost "></span> </div>
              <div class="product-add"> <span class="bg"> - </span> <span ng-bind="tsfooditem.todays_menu_qty"></span> <span class="bg"> + </span> </div>
            </div>
            
          </div>
        </div>
     
       
      </div>
	  </div>
&#13;
&#13;
&#13;

使用angularjs version1.2.13.I需要以下指定的输出

O / P

时间段12.30-4.30pm

油, 蔬菜

时间段1.30-3.30pm

油, 肉

我在另一个内部使用两个ng-repeat。但是数组总是只显示第二个插槽,.ie第二个覆盖firstone。请帮助,提前谢谢

1 个答案:

答案 0 :(得分:0)

看起来你的问题是你的第一个ng-repeat,tsfooditems不是一个数组,它是一个对象文字。 Ng-repeat仅适用于数组。尝试更改

$scope.tsfooditems ={};
$scope.tsfooditems = d[0];

$scope.tsfooditems = [];
$scope.tsfooditems.push(d[0]);