我正在对表单进行验证,以检查输入的数字是否大于某个数字。我尝试了这个答案,但仍然遇到同样的错误。
但出现以下错误:
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.
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
<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>
Run Code Online (Sandbox Code Playgroud) 我正在尝试将字符串格式应用于来自资源文件的字符串。
<p class="note">@((MarkupString)(String.Format(Localizer["Test"], 2)))</p>
Run Code Online (Sandbox Code Playgroud)
但这是它在浏览器中的显示方式:
You have done <span class="text-primary text-bold"> 2 </span> tests.
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能让它采取正确的造型?
我已经尝试过这个解决方案,但它说:
The type or namespace name 'HtmlSanitizer' could not be found
Run Code Online (Sandbox Code Playgroud)
我正在使用 Blazor 服务器和 .NET6
编辑:我有一个名为 App.resx 的文件
<data name="Test" xml:space="preserve">
<value>
You have done
&lt;span class="text-primary text-bold"&gt;
{0}
&lt;/span&gt;
tests.
</value>
</data>
Run Code Online (Sandbox Code Playgroud)