推入AJAX内部成功未更新ng-repeat

时间:2019-02-08 04:27:40

标签: javascript jquery angularjs ajax angularjs-ng-repeat

我有一个ng-repeat循环遍历$ scope.events,在ajax的成功函数中,它将json字符串推入$ scope.events数组中。但是,成功函数中推送的索引不会在ng-repeat中显示,但是会显示索引{name:“ test”,date:“ test”}。 HTML:

   <li ng-repeat="event in events"><
text class="Name" ng-bind="event.name"></text><text class="Date" ng-bind="event.date"></text>
</li>  

JS:

var table_important = angular.module('table-important', []);
table_important.controller('important-ctrl', function($scope) {
    $scope.events = [{name:"test", date:"test"}];    
    $.ajax({
            type: "POST",
            cache: false,
            data:{"d":""},
            url: "/getImportantEvents",
            dataType: "json",
            success: function(data) {                 
                $.each(data.arr, function() {                                      
                $scope.events.push( {name:this.name, date:this.date} );


  });
            },
            error: function(e) {                
                console.log(e);
            }
        });    

});

0 个答案:

没有答案