[英]Able to use a component from another module which is not being exported
我能夠從路由中的另一個模塊導入一個組件,該組件沒有被導出。
路由模塊
{
path: 'home',
component: DashComponent
}
B路由模塊
{
declarations: [DashComponent],
}
從上面的代碼中可以看出, DashComponent
沒有在 B 路由模塊中導出,但我仍然可以在 A 路由模塊中使用它而沒有任何錯誤。 為什么 ?
在模塊A,必須有export class DashComponent
和模塊B,你必須直接導入DashComponent
使用import { DashComponent } from '../moduleB/dash.component'
。
現在這是一個完美的js export-import ,所以沒有錯誤。
其次,模塊(A) 的導出屬性控制另一個模塊(B) 將訪問的內容,如果它導入此模塊(A),則無需單獨從該模塊(A) 導入所有其他導出,因此使事情變得方便和系統。 但是它不能阻止您直接從其他模塊導入導出,就像您所做的一樣(但這樣做會破壞使用模塊的全部意義)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.