【发布时间】:2021-05-22 22:11:56
【问题描述】:
我正在对表单进行验证,以检查输入的数字是否大于某个数字。 我试过这个answer,但我仍然遇到同样的错误。
但我收到以下错误:
error TS2531: Object is possibly 'null'.
<small style="color: red;" [hidden]="myForm.get('checkAmount').hasError?'maxlength'">
~~~~~~~~
src/app/withdraw/withdraw.component.ts:10:16
10 templateUrl: './withdraw.component.html',
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component WithdrawComponent.
这是我的代码:
<form [formGroup]="myForm" class="space" method="POST" autocomplete="off">
<input type="text" name="amount" size="230" placeholder="Amount To Withdraw"
formControlName="checkAmount"
[(ngModel)]="model.Balance"
maxlength=50
>
<small style="color: red;" [hidden]="myForm.get('checkAmount').hasError?'maxlength'">
The value should not exceed the balance
</small>
</form>
【问题讨论】:
-
myForm?.get('checkAmount')?.hasError?.'maxlength'"
标签: angular