小编Rid*_*loo的帖子

对象在 Angular Form 验证中可能为“null”

我正在对表单进行验证,以检查输入的数字是否大于某个数字。我尝试了这个答案,但仍然遇到同样的错误。

但出现以下错误:

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)

angular

1
推荐指数
1
解决办法
3499
查看次数

MarkupString 无法按预期与 Blazor 中的 String.Format 配合使用

我正在尝试将字符串格式应用于来自资源文件的字符串。

<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 
      &amp;lt;span class="text-primary text-bold"&amp;gt; 
        {0}
      &amp;lt;/span&amp;gt;
      tests.
    </value>   
</data>
Run Code Online (Sandbox Code Playgroud)

c# blazor blazor-server-side .net-6.0

0
推荐指数
1
解决办法
521
查看次数

标签 统计

.net-6.0 ×1

angular ×1

blazor ×1

blazor-server-side ×1

c# ×1