我有一个带有以下标记的父组件
<div class="row">
<div class="col-xs-12">
<router-outlet>
</router-outlet>
</div>
</div>
我需要将输入属性设置为将根据路径呈现的组件 . 显然,我不能使用HTML标记这样做 .
我也不能使用组件解析器,因为我的子组件 extend 是重用常用方法的父组件 . 如果我在父类中导入子组件,Webpack会抱怨循环依赖 .
简而言之, Child Component HTML
<button (click)="dosomething()"></button>
<span>{{sample}}</span>
Child Component TS
@Input() sample: number;
class Child extends parent{
}
Parent Component TS
class Parent{
stateVariable: number;
protected dosomething(){
stateVariable++;
// I need to then pass the state variable to the child component, in this case, the `sample` variable
}
}
当我有子组件标签而不是路由器插座时,此设置有效 . 有什么办法,我能做到吗?