Reputation: 10624
I have 2 sub-modules(ClientModule and AdminModule) under the root module(AppModule).
And I have a common library component (file-uploader) which I want to use in both child component.
So I simply declared the common library component in root module and use it in child module, then I got an error,
If 'app-file-uploader' is an Angular component, then verify that it is part of this module.
And If I declare that in each sub-modules, it works.
But I just want to declare the common libraries in root modules so that all child modules could use it. is it possible? if so, how to do that?
// root module
@NgModule({
imports: [
...
ClientModule,
AdminModule,
],
declarations: [
FileUploaderComponent //(x)
],
...
})
export class AppModule { }
// file-uploader
@Component({
selector: 'app-file-uploader',
templateUrl: './file-uploader.component.html',
})
export class FileUploaderComponent {
public constructor() {}
}
Upvotes: 1
Views: 1286
Reputation: 658255
If you want to use declarations from another module, you need to import that other module. There is no way around that. Each module needs to make its dependencies clear. There are no global components, directives, or pipes. Only services can be provided globally.
Upvotes: 3