2015-06-09 24 views
0

我有問題,更換我的NG-重複 我的HTML NG-內部應用程序Drupal的AngularJS AJAX簡單NG重複更新

<a href="#proceed" ng-click="order.submitOrderAjax()"> 
    <?php print t('Finish order'); ?> 
</a> 

<ul> 
    <li ng-repeat="error in order.errors">{{ error.text }}</li> 
</ul> 

控制器app.js

app.controller('orderController', function() { 
this.errors = []; 
this.submitOrderAjax = function(){ 
var data = {} // some data here like name, phone 
jQuery.ajax({ 
    type: 'POST', 
    url: Drupal.settings.basePath + 'ajax/submit_cart', 
    data: { 'order': data }, 
    dataType: 'json', 
    success: function(response){ 
     if(response.status == true){ 
      var link = response.link.replace(/\\\//g, "/"); 
      window.location.href = link; 
     }else{ 
      this.errors = response.errors; 
      console.log(this.errors); 
     } 
    }, 
}); 
}; 

的console.log返回我需要但ng重複沒有更新

回答

0

實際上html呈現在響應之前,所以你需要渲染ng-重複後

<a href="#proceed" ng-click="order.submitOrderAjax()"> 
    <?php print t('Finish order'); ?> 
</a> 

<ul ng-if="flag"> 
    <li ng-repeat="error in order.errors">{{ error.text }}</li> 
</ul> 

控制器

app.controller('orderController', function($scope) { 
    this.errors = []; 
$scope.flag=false; 
    this.submitOrderAjax = function(){ 
     var data = {} // some data here like name, phone 
     jQuery.ajax({ 
      type: 'POST', 
      url: Drupal.settings.basePath + 'ajax/submit_cart', 
      data: { 'order': data }, 
      dataType: 'json', 
      success: function(response){ 
       if(response.status == true){ 
         var link = response.link.replace(/\\\//g, "/"); 
         window.location.href = link; 

       }else{ 
        this.errors = response.errors; 
        console.log(this.errors); 
$scope.flag=true; 
       } 
      }, 
      }); 
     }; 
+0

太謝謝你了 – Victor