2013-07-23 17 views
0

我用ajax獲得數據,然後我需要在我的視圖中顯示它,並且使用ng元素重複使用DOM元素的同位素。所以,我需要調用$ scope。$ apply();然後我得到錯誤:「消化已在進行中」。AngularJS ng-repeat與同位素和AJAX

我試圖使用「安全應用」,但範圍的階段總是消化,所以應用不會觸發。我需要的只是ng-repeat的回調。

現在我有這樣的事情:

$http({ 
    method: 'GET', 
    url: '/web/main/json' 
}).success(function (data, status, headers, config) { 
     $scope.cards = data.cards; 

     /* without this apply my DOM elements would be 
     invisible (if i use isotope on them)*/ 
     $scope.$apply(); 
     mainFunction(); // here i use isotope on my DOM elements 
    }).error(function (data, status, headers, config) { 
     alert("fail " + data); 
    }); 
+0

mainFunction()是做什麼的? – noj

+0

類似這樣的: $(「#容器).isotope(...); –

回答

1

我想你應該改變你的方法。閱讀關於指令和寫指令應用同位素適用同位素它在使用標籤的孩子,然後創建類似:

<tag1 apply-isotope> 
    </tag2 ng-repeat="card in cards"> 
    ... 
    </tag2> 
</tag1> 
+0

對於這樣一個遲到的批准抱歉:) –

0

嘗試這樣的。

$http({method: 'GET', 
    url: '/web/main/json', 
    **headers: { "Content-Type": "application/json; charset=UTF-8"}** 
    }).success(){}).error(function() {});