After a day of search found nothing what i am looking for !
i have some methods (also can say services) which i have written in the separate file then i have to use those methods throughout the whole angular2 app. i know if we import that file at the time of bootstrap we able to use those methods in the whole app. but my question is what if i have to more than two global files. should i have to import all files in the constructor of every component (in which components service required)? or is there any other alternate ?
for example i have file named GlobalService.ts.
export clas xyz{
constructor(private base_path_service: GlobalService){
//stuff...
}
}
Q1:- Is there any alternate to avoid initializing of GlobalService every time in the constructor ?
Q2:- whats the benifit of use @injectable
and @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 one is best and why ?