2017-09-14 67 views
0
<div class="gridly-static"> 
    <div id={{y.id}} ng-repeat="y in Categories" ng-init="initCategories()"> 
    <div class="title">{{y.name}}</div> 
    </div> 
</div> 

分類變量通過$ http.get(從API服務獲取),和NG-INIT通話initCategories是動態使用jquery-gridly的兩件事情.The組合使重置佈局我的Chrome停止響應(該選項卡也根本無法關閉)angularjs和jQuery的衝突導致鉻停止responsing

當我將類別更改爲對象(不從互聯網獲取)時,代碼工作查找。此外,當我不使用$('xxx')。gridly()初始化佈局時,它也可以工作。

我知道結合angularjs和jQuery是一個壞主意。然而,爲什麼代碼使鉻停止運行困惑我(循環?由角度手錶引起的東西?)

+0

您是否嘗試過使用jQuery( '#idElement')來代替$ ...? –

+0

url中的示例https://api.jquery.com/jquery.noconflict/ –

回答

0

許多JavaScript庫使用$作爲函數或變量名,就像jQuery一樣。在jQuery的情況下,$是jQuery的別名,所以所有功能都可以在不使用$的情況下使用。如果您需要在jQuery旁邊使用另一個JavaScript庫,請使用$ .noConflict()調用將$ control的控制權返還給其他庫。 $的舊引用在jQuery初始化期間保存; noConflict()只是簡單地恢復它們。

<script src="other_lib.js"></script> 
<script src="jquery.js"></script> 
<script> 
$.noConflict(); 
jQuery(document).ready(function($) { 
// Code that uses jQuery's $ can follow here. 
}); 
// Code that uses other library's $ can follow here. 
</script> 

詳情Documentation