2014-03-14 178 views
1

ng-view通過路由換出。下面是一些途徑和控制器代碼

var containers = []; 
angular.module('AContainer',['ngRoute']).config(
function ($routeProvider){ 
    $routeProvider 
    .when('/', { 
     controller: containerListCtrl, 
     templateUrl: '/closeAndUplift_containerList.html' 
    }); 
} 
); 
function containerListCtrl($scope, $location){ 
    $scope.containers = containers; 
} 

這裏的是div

<div id='containersDiv' ng-app='AContainer'> 
    <div ng-view></div> 
</div> 

在此的圖(closeAndUplift_containerList.html)已經被加載,其經由納克重複顯示對象的數組

<div> 
<table> 
    <thead> 
    <th>Pallet id</th> 
    </thead> 
    <tr ng-repeat='container in containers'> 
     <td><a href='#/edit/{{container.index}}'>{{container.id}}</a></td> 
    </tr> 
</table> 

,會出現問題時從jqu的變化結果ery ajax回調。 xhr調用被包含在一個單獨的庫中,並且傳入一個回調函數。回調應該清除容器列表。回調執行此:

var activeScope = $('#containersDiv').scope(); 
activeScope.$apply(function(){ 
    activeScope.containers = []; 
}); 

但沒有任何反應。舊的值仍在顯示。

編輯: 根據Rishul的建議,我重新安排了利用$ http的代碼,以使其工作。問題是,雖然這是一種解決方法,但它並沒有真正回答爲什麼我使用的方法不起作用的問題。 有人可以評論他的答案是否應該選擇爲解決問題?

+0

您的看法需要一個控制器,將有一個範圍 –

+0

謝謝廣告,我已經更新了問題 –

+1

出於興趣:你需要什麼jQuery的回調? Angular有一些內置的xhr請求的東西。 – Jorg

回答

1

使用$ HTTP服務,使AJAX調用,因爲這種內在的角度JS庫將在得到一個響應運行摘要週期和修改變量的作用域的看法也會發生變化。

你的情況jquery回調不會觸發$摘要循環,因此視圖沒有得到更新!請確認它是否工作