简体   繁体   中英

Angular 2 : scope of services in lazy loaded modules

I'm new to Angular 2 and working on a pre-existing template ( here ).

I'm trying to use ng2-translate but I have trouble using it globaly .

I have a layout module which declares some components (sidebar, navbar, notifications etc) and imports ng-translate service. In all of those components, I can access the translation service.

But, in this layout, I also have a Route which imports all content modules.

在此处输入图片说明

All the imported modules (dashboard, offers, contacts, agenda) can't access the translation service.

I do not want to declare ng-translate in every child module, how can they access it ?

Like I said, I'm new to Angular 2 and I'm completly lost in all these imports/delcarations/exports. Any help is appreciated.

Ps : sorry for bad english.

Ok, I figure it out.

First, I learn that what I'm doing with loadChildren is called Lazy loading (we learn every day). From that, research are easier.

I found the solution here :

https://github.com/ocombe/ng2-translate/issues/209

I don't really understand why but it's working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM