NavigationItem
然后用电线把它们连接起来
Router
. 下面是一个例子
NavigationItemFactory
// imports
@Injectable({ providedIn: 'root' })
export class NavigationItemFactory {
constructor(private router: Router) { }
createItem(): NavigationItem {
return new NavigationItem(this.router);
}
}
因为它使用角6+
providedIn
特性,您不需要在模块中声明这个工厂类,这使得它很容易在项目之间移动。
只要在项目中的任何地方创建这些项,就可以依赖
导航项工厂
createItem
相应地发挥作用。诚然,这仍然是您在项目中需要的依赖项,但至少现在它是您自己类型的依赖项,而不是依赖项
路由器
它本身