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