Angular之RouterModule的forRoot與forChild


Angular 提供了一種方式來把服務提供商從模塊中分離出來,以便模塊既可以帶着 providers 被根模塊導入,也可以不帶 providers 被子模塊導入。

區別:

`forRoot` creates a module that contains all the directives, the given routes, and the router service itself

`forChild` creates a module that contains all the directives and the given routes, but does not include the router service.

RouterModule的元數據

@NgModule({
    declarations: ROUTER_DIRECTIVES, 
    exports: ROUTER_DIRECTIVES
})

RouterModule定義的指令

const ROUTER_DIRECTIVES = [RouterOutlet, RouterLink, RouterLinkWithHref, RouterLinkActive];

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM