2015-01-09 61 views
0

我非常想嘗試使我的第一個網頁初學者。我正在使用帶角度路線的角度。每個入門文檔包含所需photoswipe html的頁面被注入index.html。我得到以下錯誤。 「未捕獲類型錯誤:無法讀取屬性‘則firstChild’的未定義」,其指向行photoswipe.js的66(VAR節點= ....)Photoswipe with angularJS pswp undefined

getChildByClass: function(parentEl, childClassName) { 
    var node = parentEl.firstChild; 
    while(node) { 
     if(framework.hasClass(node, childClassName)) { 
      return node; 
     } 
     node = node.nextSibling; 
    } 

通過我結束與非常的代碼之後parentEL向上根據入門文檔再次提供所需js的第一行。

var pswpElement = document.querySelectorAll('.pswp')[0]; 

添加console.log(pswpElement)返回undefined,我認爲這是根本問題。該文件說,class = pswp必須是photoswipe的根元素的類。它在我的路由定義中爲/ gallery注入的html頁面的根元素中。我也嘗試將它添加到每個元素,包括在我的index.html頁面中包含ng-view的div。 pswpElement總是回到未定義狀態。

任何幫助集成photoswipe與角度將不勝感激。

回答

3

我有同樣的問題,如果您有jQuery或其他JavaScript工具啓用,只有在頁面完全加載後運行photoswipe函數。

$(document).ready(function() { 
    openPhotoSwipe(); 
}); 

您需要的javascript封裝在一個功能你的HTML,或移動的JavaScript到頁面底部的photoswipe ..

「未定義」錯誤出現,因爲它試圖啓動搜索對於.pswp類,當它們尚未加載時...