Dav*_*ine 8 angular-routing viewchild angular
我正在寻找@ 这个SO Q&A,并想知道是否有可能有一个基地abstract class呢?而不是一个interface,是有可能有在那些经由父组件访问的子组件的基类的不同的实现@ViewChild在装饰Angular2?
理想情况下,我想为通过父实例化实例化的子组件提供一种方法,Router以便能够调用父路由器 - 这有意义吗?我希望孩子能够打电话parentRouter.navigate(["SomeOtherRoute", { args: 'blah' }]);.
我最初的方法是让子组件实现一个基类,父组件将通过@ViewChild装饰器获得引用.父级将subscribe尝试调用导航事件的子操作,并且其处理程序将调用router.navigate(因为它具有父级别的路由器).
实际上很简单。例如,如果您有一个EmployeeComponent类,它扩展了PersonComponent这是一个抽象类。
您可以通过在EmployeeComponent中添加以下内容使其变得平易近人:
providers: [ {provide: PersonComponent, useExisting: EmployeeComponent }]
并在容器组件中使用ViewChildren()或ContentChildren(),如下所示:
@ViewChildren(PersonComponent) public persons: QueryList<PersonComponent>;
| 归档时间: |
|
| 查看次数: |
3781 次 |
| 最近记录: |