Able to use a component from another module which is not being exported

Viewed 89

I'm able to import a component from another module in routing which is not being exported.

A routing module

{
    path: 'home',
    component: DashComponent    
}

B routing module

{
    declarations: [DashComponent],
}

As seen in the above code, DashComponent is not being exported in B routing module but still I'm able to use it in A routing module without any errors. Why ?

1 Answers

In module A, there must be export class DashComponent and in module B you must be directly importing the DashComponent using import { DashComponent } from '../moduleB/dash.component'.

Now this is a perfectly fine js export-import, so there is no error.

Second, the export property of a module(A) controls what the another module(B) will get access to, if it imports this module(A), without you having to import every other export from that module(A) separately, thus making things convenient and systematic. But it cannot stop you from importing the exports directly from other modules, like you did (but doing this ruins the whole point of using modules).

Related