我用一個指令Imageonload來管理我的圖片加載預載:ImageonLoad指令AngularJS
Directive.js
.directive('imageOnload', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('load', function() {
// call the function that was passed
scope.$apply(attrs.imageOnload);
// usage: <img ng-src="src" image-onload="imgLoadedCallback()" />
});
}
};
});
Controller.js
$scope.imgLoadedCallback=function(map){
map.flag=false;
};
Viewer.html
<img src="images/loading_bar.gif" ng-show="mapAllDataSets[$index].flag" >
<img class="img-responsive center-block" ng-src="{{mapAllDataSets[$index].src}}" image-onload="imgLoadedCallback(mapAllDataSets[$index])" >
這是w只要我不試圖連續顯示相同的圖像,就可以正常工作。
如果我調用相同的圖像,我的預加載器將不會隱藏。我不明白爲什麼。
你能不能做一個(基本,簡單)plunker或小提琴和張貼鏈接?這將更容易找到錯誤。 – akashrajkn