2014-10-28 21 views
0

我的一些指令的链接函数需要相当长的时间来执行。所以它延迟了页面加载时间。通过延迟执行指令链接功能来加快页面加载时间

为了使速度更快,意图是在window.onload事件之后执行linkfn。

,我打算采取

directive('mydirective', function(){ 
    restrict: 'A', 
    scope:{}, 
    link : function(scope, element, attrs) { 
    var unwatcher = scope.$watch("$viewcontentloaded", function(){ 
     unwatcher(); 
     //actual link function which takes too much time to execute. 
    }); 
    } 
} 

顺便说一句,使用$超时的方法(linkfn,0)并不能保证它window.onload事件 more info后执行。

还有其他更好的选择吗?在https://github.com/Pasvaz/bindonce

回答

0

结账bindonce尝试模板加载HTML范本:中代替templateUrl:如果你是不是已经