亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ngRoute 如何添加loading

ngRoute 如何添加loading

眼眸繁星 2019-02-06 14:15:51
想在每個頁面圖片加載完之前添加一個loading,等到圖片加載完再顯示頁面,求思路
查看完整描述

2 回答

?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

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

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

(3)如果是html 里的image 標簽,我不知道有事件可以判斷image加載完成,如果有好的方式,請回復,共同學習。


查看完整回答
反對 回復 2019-02-25
?
翻閱古今

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');




查看完整回答
反對 回復 2019-02-25
  • 2 回答
  • 0 關注
  • 442 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號