provide httpProvider 中注入指令injecto

provide httpProvider 中注入指令injector

今天遇到一個問題,在provide中注入指令

export class globalProvider {
    static $inject = ['$provide',"$injector"];
    constructor($provide: ng.IParseProvider, $injector: ng.auto.IInjectorService) {    

        let initInjector = angular.injector(['ng']);
        let $http = <ng.IHttpService>initInjector.get('$http');
        let $window = <GlobalDefinitionInterface>initInjector.get('$window');
        $http.get("config/ClientConfig.json").then(function (response:any) {
            $window["rootConfig"] = response.data;
            console.log( $window["rootConfig"] );
            console.log($window["rootConfig"].hempConfig.kpPath+"--------------------------kpPath")            
        });

    }
}

今天遇到一個問題,在httpProvider 中注入指令

import { LoginServiceInterface } from './loginService';

export  class httpProvider {
    static $inject = ['$httpProvider'];
    constructor($httpProvider: ng.IHttpProvider) {         
        // set default http request CORS with credentials
        $httpProvider.defaults.withCredentials = true;
        // interceptor for all http request
        $httpProvider.interceptors.push(['$q', '$window', '$log', '$injector', '$rootScope', '$cookies', function($q: ng.IQService, $window: GlobalDefinitionInterface,
            $log: ng.ILogService, $injector: ng.auto.IInjectorService, $rootScope: ng.IRootScopeService, $cookies: ICookiesService) {
            return {
                // optional method
                'request': function(config) {
                    if ($window.rootConfig !== undefined &&
                        $window.rootConfig.hempConfig.basePath.length < config.url.length &&
                        config.url.substr(0, $window.rootConfig.hempConfig.basePath.length) === $window.rootConfig.hempConfig.basePath &&
                        $window.basicAuthHeaderValue !== undefined &&
                        $window.basicAuthHeaderValue !== null) {
                        config.headers['Authorization'] = $window.basicAuthHeaderValue;
                           console.log("----httpProveide==1111====監聽======$window===");
                        config.timeout = 90000;//指定請求超時時間
                    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章