2015-08-22 30 views
0

我知道MDL js組件(如文本區域,菜單和選項卡)在文檔加載時默認加載和升級,但在使用角度路徑時不會發生在模板上。在這一點上,我用這一點,但它只是讓我的組件正常工作時,用戶通過第二次訪問的觀點:如何在使用Angular路線時升級Material Design Lite js組件?

$scope.$on('$routeChangeStart', function() { 

    $document.ready(function() { 
     componentHandler.upgradeDom(); 
    }); 

}); 

有反正到組件升級模板上的用戶輸入之前第一次看,或類似的東西?我被困在這個問題上。

+0

我不是超級熟悉MDL,但你可能會發現[這](https://github.com/google/material-design-lite/issues/1175 )或[this](https://github.com/google/material-design-lite/issues/1165)有用。 –

+0

我來看看。非常感謝@SeanWalsh。 – Eric

+0

我爲我的案子找到了一個簡單的解決方案@SeanWalsh,謝謝你。 代替使用$的document.ready,我使用只是一個的setInterval(),就這樣: 'code'的setInterval(函數(){ componentHandler.upgradeDom();} ,200); 'code' – Eric

回答

2

這爲我工作

angular.module(...) 
.run(function($rootScope, $location, $timeout) { 
    $rootScope.$on('$viewContentLoaded', function() { 
     $timeout(function() { 
      componentHandler.upgradeAllRegistered(); 
     }); 
    }); 
}) 
相關問題