在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5  HTML/ ngRoute 如何添加loading

ngRoute 如何添加loading

想在每個(gè)頁面圖片加載完之前添加一個(gè)loading,等到圖片加載完再顯示頁面,求思路

回答
編輯回答
夏木
2018年8月14日 22:59
編輯回答
陌離殤

(1)如果圖片是從后端請(qǐng)求獲取到的,可以在請(qǐng)求完成后設(shè)置一個(gè)布爾值的狀態(tài),在頁面里ngif判斷去顯示loading 或者圖片;

(2)如果圖片是從function 來寫入,可以 function load(){} 完成后,同(1)去做;

(3)如果是html 里的image 標(biāo)簽,我不知道有事件可以判斷image加載完成,如果有好的方式,請(qǐng)回復(fù),共同學(xué)習(xí)。

2017年9月12日 14:25
編輯回答
深記你
可以考慮使用angular 的攔截器機(jī)制,實(shí)現(xiàn)全局的請(qǐng)求攔截
//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) {
            //     // 處理各類自定義錯(cuò)誤
            //     //$rootScope.httpLoading=false;
            //     msg("服務(wù)出問題拉,聯(lián)系系統(tǒng)維護(hù)人員吧");

            //     console.log(err);


            // } else if(404 == err.status) {

            //     msg("服務(wù)找不到了,請(qǐng)聯(lián)系維護(hù)人員!")

            // }else if(403  == err.status) {
            //     msg("登錄狀態(tài)已過期,請(qǐng)重新登錄!",function () {
            //         logout();
            //     });

            // }else{
            //     msg("服務(wù)找不到了,請(qǐng)聯(lián)系維護(hù)人員!",function () {
            //        // logout();
            //     });

            // }


            $rootScope.httpLoading=false;
            return $q.reject(err);
        }
    };

    return loadingInjector;

}]);

最后在 app.config 中注入
$httpProvider.interceptors.push('httpLoadingInjector');


2017年5月1日 12:53