2013-12-10 146 views
0

引導模式我有簡單的角控制器,用於我的模態窗口故障與角

var ModalDialogCtrl = function ($scope) { 
    $scope.data; 
}; 

而且我從D3的動態生成的數據(我不能使用該內容NG-點擊)。我設置的事件在D3​​的onclick是這樣的:

.on("click", function(d, i) { 
     //get some data   
     angular.element($('#modalDialog')).scope().data = data; 
     $('#modalDialog').modal('show'); 
    }) 

對話框顯示沒有任何數據,但是當我關閉它,數據顯示在它(關閉動畫與模態數據!)。當我的對話框顯示時,如何更新數據?!

dialog first opening

dialog second opening and first hiding

而且我的對話框代碼:

<div class="wrapper"> 
    <span> 
     <span class="modal-table-header" data-dismiss="modal" ng-click='cancel()'>close</span> 
     <a class="close" data-dismiss="modal" ng-click='cancel()'><span class="icon-remove-circle icon-bold"></span></a> 
    </span> 
    </br> </br> 
    <table style="display: list-item;"> 
     <thead> 
     <tr> 
      <th>{{data[0].headerName}}</th> 
      <th ng-repeat="subData in data[0].subData">{{subData.category}}</th> 
     </tr> 
     </thead> 
     <tbody> 
     <tr ng-repeat="item in data"> 
      <td>{{item.header}}</td> 
      <td ng-repeat="subData in item.subData">{{subData.value}}</td> 
     </tr> 
     </tbody> 
    </table> 
</div> 

回答

0

你需要一個$apply讓角知道數據發生了變化:

angular.element($('#modalDialog')).scope().data = data; 
    angular.element($('#modalDialog')).scope().$apply(); 
    $('#modalDialog').modal('show'); 

第一次你打開dia在設置data後立即記錄日誌,沒有$digest循環執行並且角度不知道scope.data已更新。在顯示模態對話框之前,明確調用$apply將讓角度知道更改。

但是,在第二次打開模態之前,我懷疑$digest循環已經作爲其他某個動作的副作用而被執行,因此您會看到數據。

+0

哦。現在一切正常!謝謝 –