Closed msyesyan closed 2 years ago
[https://stackblitz.com/edit/ng-zorro-antd-ivy-uda7th] (https://stackblitz.com/edit/ng-zorro-antd-ivy-uda7th)
Open the reproduction link directly, click the button, you should switch the Disabled status, but no
Click the button to Toggle Disabled status
Not reflected
ENVIRONMENT | INFO |
---|---|
Ng-Zorro-ANTD | 12.0.1 |
Browser | Chrome |
Our actual code is 12.0.1, but StackBlitz is a 11 version, but it is actually the same, and the same problem is that the STACKBLITZ link is the code of V11, and it is too much trouble. The following strategy is required in our code: ONPUSH strategy
Hi, @msyesyan. There are some mistakes made in your reproduction. A better way to manipulate formControl's disabled:
@Component({
selector: 'nz-demo',
template: `
<form [formGroup]="formGroup">
<button nz-button nzType="primary" (click)="toggle()"> Enable </button>
<textarea nz-input formControlName="text"></textarea>
</form>
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class NzDemoInputBasicComponent {
formGroup: FormGroup;
private _disable = false;
constructor(private cdr: ChangeDetectorRef) {
this.formGroup = new FormGroup({
text: new FormControl({ value: '', disabled: false })
});
}
toggle(): void {
if (this._disable) {
this.formGroup.get('text')?.enable();
} else {
this.formGroup.get('text')?.disable();
}
this._disable = !this._disable;
this.cdr.markForCheck();
}
}
thanks,
Reproduction link
https://stackblitz.com/edit/ng-zorro-antd-ivy-uda7th
Steps to reproduce
直接打开重现链接,点击按钮,应该可以切换 disabled 状态,但是并没有
What is expected?
点击按钮,可以 toggle disabled 状态
What is actually happening?
没反映
我们实际代码是 12.0.1, 但是 stackblitz 里是 11 版本,但其实都一样,12 也有同样问题,只不过那个 stackblitz 链接给的是 v11 的代码,自己换 12 又太麻烦了。我们代码中需要如下策略: