dependency injection - Global/Common Methods Constants Services throughout whole App angular2 -


after day of search found nothing looking !

i have methods (also can services) have written in separate file have use methods throughout whole angular2 app. know if import file @ time of bootstrap able use methods in whole app. question if have more 2 global files. should have import files in constructor of every component (in components service required)? or there other alternate ?

for example have file named globalservice.ts.

export clas xyz{  constructor(private base_path_service: globalservice){    //stuff...     } } 

q1:- there alternate avoid initializing of globalservice every time in constructor ?

q2:- whats benifit of use @injectable , @inject while service injection ?

q3:-

export clas xyz{  constructor(private base_path_service: globalservice){    //stuff...     } } 

or

class xyz{   constructor(@inject(globalservice) globalservice: globalservice) {       //stuff....   } } 

which 1 best , why ?

q1: there no sane alternative.

q2: @injectable() has added services have constructor arguments otherwise angulars di can't create instances.

@inject(globalservice) redundant. there special features @inject() helpful shown here https://stackoverflow.com/a/35217704/217408

q3: first example. see q2.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -