2017-06-30 3 views
1

Ich schiebe ein neues Objekt in das Array, aber konnte den neuen Wert nicht auf der Benutzeroberfläche aktualisiert sehen. Ich benutze angular js hier und aktualisiere einen Wert. Hier ist mein Code.Liste nicht aktualisieren neues Objekt in angularjs?

html

<ul id="list-wrapper-noti" class="dropdown-menu dropdown-menu-right style-3" > 
    <div infinite-scroll-disabled = "disableScroll" infinite-scroll='loadMoreNotifications()' infinite-scroll-distance='0' infinite-scroll-container="'#list-wrapper-noti'"> 
     <li > 
      <a href="list.php?id=20" style=" color:#3C71C1; padding-top: 3px">See all </a> 
      <a class="pull-right" href="list.php?id=20" style=" color:#3C71C1;">Mark all as read </a> 
    </li> 
    <li style="height: 30px"></li> 


    <li ng-repeat = "notification in notifications track by $index"> 
     <a style="text-decoration:none; color:#534D4D" href="{{notification.href}}" > 
     <div class="media"> 

    <img src="https://papa.fit/routes/images/inst_logo/default.png" alt="fakeimg" class="img-circle pull-left" style="height:50px; width:50px;"> 

     <div class="media-body"> 
     <div class="media">{{notification.employee}} {{notification.action | lowercase}} {{notification.element}} {{notification.record_value}}</div> 
      <span class="muted">{{notification.time_string}}</span> 
     </div> 

     </div> 
    </a> 
    <div class="divider"></div> 
</li> 

Controller

function addNewNotification(new_noti){ 
     var obj = {"action":new_noti.data.action,"element":new_noti.data.element,"record_value":new_noti.data.record_value,"time_string":new_noti.data.time_string,"employee":new_noti.data.employee}; 
     $scope.notifications.unshift(obj); 
     console.log($scope.notifications) 

    } 

und von hier Ich rufe diese Func

Ich weiß nicht, warum es nicht aktualisiert wird nach dem Push in Array.please jemand helfen?

+0

hat Ihr log (console.log ($ scope.notifications) erscheint – Faly

+0

was Nutzlast – Dixit

+0

ja @Faly Ich habe neue obj in?. Array und auch auf der Konsole gedruckt –

Antwort

0

Inject $ timeout in Ihrem Controller und versuchen Sie dies:

$timeout(function() { 
    $scope.notifications.unshift(obj); 
}); 
+0

Dank @Faly. Sie haben meinen Tag gemacht. –

Verwandte Themen