Closed ghost closed 7 years ago
Hey there! If you want to use a directive from inside another module, you also might need to import the promise button module there, too, e.g.:
@NgModule({
imports: [
Angular2PromiseButtonModule.forRoot(),
// or maybe like this here, not sure:
Angular2PromiseButtonModule,
],
})
export class AuthModule { }
I'm not sure, but it might be that you can skip out the forRoot part.
@johannesjo thanks, it helped. I imported the module in my child module and now it works. The .formRoot() part was mandatory by the way.
Is there any way to import this module only once in the global module? For example, I import ToasterModule only in my parent module and it works everywhere, including my child modules
@maxkorz that's interesting. I'll check out, how they do this. Maybe I'm missing something.
Weirdly I'm unable to find any difference from how the modules are declared: https://github.com/Stabzs/Angular2-Toaster/blob/master/src/toaster.module.ts https://github.com/johannesjo/angular2-promise-buttons/blob/master/src/angular2-promise-buttons.module.ts
And from all I've read at least with angular4 a directive should be available in other modules, too when imported like you did. I think that this might be related to the forRoot method. I'll try to dig into it a little further, but I'm glad for suggestions how to solve this while maintaining the possibility of a global config.
@johannesjo I will look into it. Something's wrong for sure. According to documentation I should not call .forRoot in child modules:
Call forRoot only in the root application module, AppModule. Calling it in any other module, particularly in a lazy-loaded module, is contrary to the intent and can produce a runtime error.
Remember to import the result; don't add it to any other NgModule list.
Thank you very much!
@maxkorz Does this work now for you?
@johannesjo Yes. I found a very useful article on angularjs scopes. Understanding Angular modules (NgModule) and their scopes.
where it says
components you declared are only usable in the current module
So I created a "shared" module and now I do all the declarations there and then I export everything. It works fine.
@maxkorz thanks for sharing! That's an interesting article!
Hello. I'm a newbie in Angular. What am I doing wrong?
My app.module.ts
in AuthModule I have a component where I do the following:
I get the following error when I open the page https://i.imgur.com/h09SYa0.png I use Angular 4.1.3.