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];