angular - Injected service is undefined, but works in other classes -


i puzzled: i inject , use loggingservice in other services , works. simple loggingservice:

import { injectable } '@angular/core';  @injectable() export class loggingservice {   //[...]     loginfo(obj: any) {     if (this.logging) console.info('[info] ' + obj);   } } 

in following class, my injected service undefined:

interceptor.service.ts

import { loggingservice } './../logging/logging.service'; import { requestoptionsargs, response } '@angular/http'; import { injectable, injector, oninit } '@angular/core'; import { ihttpinterceptor } '@covalent/http';  @injectable() export class interceptorservice implements ihttpinterceptor {    constructor(private logger: loggingservice) {     console.log('logger = ' + logger); // undefined   }    onrequest(requestoptions: requestoptionsargs): requestoptionsargs {     this.logger.logdebug(requestoptions); // not work     return requestoptions;   }    // [...] other methods } 

app.module.ts

import { interceptorservice } './services/interceptor/interceptor.service'; import { covalenthttpmodule, ihttpinterceptor } '@covalent/http'; import { loggingservice } './services/logging/logging.service';  @ngmodule({    imports: [     // [...]     covalenthttpmodule.forroot({       interceptors: [{         interceptor: interceptorservice, paths: ['**'],       }],     }),   ],    providers: [     loggingservice,     interceptorservice,     // [...]   ],   bootstrap: [appcomponent] }) export class appmodule { } 

how class different other ones (where injection works ?

i tried injecting service using injector:

loggingservice : loggingservice; constructor(private injector: injector) { } // [...] loggingservice = this.injector.get(loggingservice); 

but undefined. missing ?

the ihttpinterceptor class comes following framework: https://teradata.github.io/covalent/#/components/http

with angular 4.3's httpclient, gave , wrote own interceptor. problem had related covalent's interceptor service , configuration.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -