【发布时间】:2020-06-01 03:36:55
【问题描述】:
我有一个子组件,可以在父组件中多次使用不同的操作。现在当我单击父组件中的按钮时,如何禁用子组件中存在的按钮。
我的可以多次使用的子组件:
从 'angular2/core' 导入 {Component};
@Component({
selector: 'my-product',
template: `<button [disabled]="isDisableButton">select</button>`
})
export class MyCardComponent {
@Input() isDisableButton = false;
}
我的父组件html:
<div>
<p>Product Type 1<p>
<my-product [isDisableButton]="isDisableType1Button"></my-product>
<button (click)="onType1()">select type 1</button>
</div>
<div>
<p>Product Type 2<p>
<my-product [isDisableButton]="isDisableType2Button"></my-product>
<button (click)="onType2()">select type 1</button>
</div>
我的父组件 ts :
@Component({
selector: 'my-parentComponent',
templateUrl: '..'
})
export class PopupDirective {
isDisableType1Button : boolean;
isDisableType2Button: boolean;
onType2(){
this.isDisableType1Button = true;
this.isDisableType2Button = false;
}
onType1(){
this.isDisableType2Button = true;
this.isDisableType1Button = false;
}
}
此解决方案无法正常工作
【问题讨论】:
-
你能提供stack-blitz链接吗?