【发布时间】:2020-12-31 23:52:37
【问题描述】:
我在 NgRx 工作并收到此错误:
'期待一个赋值或函数调用,却看到了一个表达式。'
this.sfForm.get('code')?.[this._mode ? 'disable' : 'enable'](); 中的声纳问题。
我不明白来自声纳的信息,以及这里要解决的问题。 我需要一些帮助来理解代码并解决问题。
<mat-form-field [formGroup]="sfForm">
<input Input
matInput
(keydown.enter)="search($event.target.value)"
[type]="''"
formControlName="code"
required>
</mat-form-field>
sfForm: FormGroup;
private _mode: boolean = true;
public set scanMode(value: boolean) {
this._mode = value;
this.sfForm.get('code')?.[this._mode ? 'disable' : 'enable']();
}
【问题讨论】:
-
this._mode ? 'disable' : 'enable'- Question mark and colon in JavaScript;[]- JavaScript property access: dot notation vs. brackets?;?.- Optional Chaining in JavaScript; What does this symbol mean in JavaScript? -
this.sfForm.get('code')?将以 null 安全的方式获取'code'的值,然后[this._mode ? 'disable' : 'enable']将从该结果中获取'disable'或'enable'属性,具体取决于this._mode, 最后获取的任何内容都将作为带有()的函数执行
标签: angular typescript ngrx angular-reactive-forms