2017-06-12 60 views
0

我有一个名为altSegments的数组,并基于$ scope.firstSeg或$ scope.lastSeg我想显示同一数组的不同部分。在大多数情况下,我将altSegments数组全部更改并更新得很好,但是当我从相同的altSegments数组转到相同的数组,但更改$ scope.firstSeg和$ scope.lastSeg时,它不会正确更新。AngularJS- ng-repeat中的项不会更新变量更新

我怀疑它与altSegments没有改变有关,因此AngularJS决定不值得再次查看代码并重新显示。我将如何解决这个问题?

<li ng-repeat="altseg in altSegments"> 
 
    <!-- For multiflight home to first --> 
 
    <div ng-show="{{firstSeg}}" ng-repeat="flights in altseg.segment_details_1.leg_details"> 
 
    <p class="small dark"> 
 
     <strong>Flight:</strong> {{flights.Carrier}} {{ flights.FlightNumber}} 
 
    </p> 
 
    <p class="small dark"> 
 
     <strong>Departure:</strong> {{flights.OriginName}} | {{flights.DepartureTime | splitDT }} 
 
    </p> 
 
    <p class="small dark"> 
 
     <strong>Arrival:</strong> {{flights.DestinationName}} | {{flights.ArrivalTime | splitDT }} 
 
    </p> 
 
    </div> 
 
    <!-- For multiflight last to home --> 
 
    <div ng-show="{{lastSeg}}" ng-repeat="flights in altseg.segment_details_2.leg_details"> 
 
    <p class="small dark"> 
 
     <strong>Flight:</strong> {{flights.Carrier}} {{ flights.FlightNumber}} 
 
    </p> 
 
    <p class="small dark"> 
 
     <strong>Departure:</strong> {{flights.OriginName}} | {{flights.DepartureTime | splitDT }} 
 
    </p> 
 
    <p class="small dark"> 
 
     <strong>Arrival:</strong> {{flights.DestinationName}} | {{flights.ArrivalTime | splitDT }} 
 
    </p> 
 
    </div>

+2

您不必在ng-show上使用插值运算符{{}} – Vivz

回答

0

它看起来像你正在使用ng-show="{{firstSeg}}"这应该是ng-show="firstSeg" ..

如果仍然不起作用, 尝试更新$ scope.apply()中控制器端的数据...

例如: -

$scope.apply(function(){ 
    list = updated_list; // put your updation of list here 
});