我想设置' readonly'在assetId字段按键期间数量字段的属性。
<!-- Asset ID Field-->
<div class="form-group">
<label for="Asset ID">Asset ID:</label>
<input autocomplete="off" type="text" class="form-control" id="assetId" name="assetId" formControlName="assetId" (keypress)="setAssetId()">
</div>
<!-- Quantity Field-->
<div class="form-group">
<label for="Quantity">Quantity:</label>
<input autocomplete="off" type="text" class="form-control" id="quantity" name="quantity" formControlName="quantity">
</div>
这是我的角度函数:
public setAssetId(){
console.log('Key changed');
this.form.controls['quantity'].patchValue(1);
this.form.controls['quantity'].set('readonly'); // I want to something like that
}
请帮我解决这个问题......
答案 0 :(得分:1)
您可以将属性设置为输入事件,如下所示:
<强>打字稿:强>
isOk: boolean;
public setAssetId(){
....
isOk = true;
}
<强> HTML 强>
<input autocomplete="off" [readonly]="isOk" type="text" class="form-control" id="quantity" name="quantity" formControlName="quantity">