2 回答

TA貢獻1797條經驗 獲得超6個贊
(1)如果圖片是從后端請求獲取到的,可以在請求完成后設置一個布爾值的狀態,在頁面里ngif判斷去顯示loading 或者圖片;
(2)如果圖片是從function 來寫入,可以 function load(){} 完成后,同(1)去做;
(3)如果是html 里的image 標簽,我不知道有事件可以判斷image加載完成,如果有好的方式,請回復,共同學習。

TA貢獻1780條經驗 獲得超5個贊
可以考慮使用angular 的攔截器機制,實現全局的請求攔截
//http loading Injector
app.factory('httpLoadingInjector',['$rootScope','$q',function($rootScope,$q) {
var loadingInjector = {
request: function(config) {
$rootScope.httpLoading=true;
return config;
},
response: function (response) {
$rootScope.httpLoading=false;
if(response.status!=200){
console.log("Response-Error:",response);
}
return response;
},
responseError: function(err){
// console.log('responseError:' + angular.toJson(err,true));
// if(500 == err.status) {
// // 處理各類自定義錯誤
// //$rootScope.httpLoading=false;
// msg("服務出問題拉,聯系系統維護人員吧");
// console.log(err);
// } else if(404 == err.status) {
// msg("服務找不到了,請聯系維護人員!")
// }else if(403 == err.status) {
// msg("登錄狀態已過期,請重新登錄!",function () {
// logout();
// });
// }else{
// msg("服務找不到了,請聯系維護人員!",function () {
// // logout();
// });
// }
$rootScope.httpLoading=false;
return $q.reject(err);
}
};
return loadingInjector;
}]);
最后在 app.config 中注入
$httpProvider.interceptors.push('httpLoadingInjector');
添加回答
舉報