我有两个错误(在html中的两个位置有相同的错误)
<label for="category"
>Category
<select
class="form-control category"
[(ngModel)]="productModel.category"
#title="ngModel"
[ngClass]="{ 'is-invalid': pf.submitted && category.invalid }"
name="category"
placeholder="Please select a Category"
required
category
>
<option value="">Please select a Category</option>
<option
*ngFor="let item of (this.categoryObj | keyvalue); let i = index"
value="{{ item.key }}"
>{{ item.key }}</option
>
</select></label
>
<div *ngIf="pf.submitted && category.invalid" class="invalid-feedback">
<div *ngIf="category.errors.required">Category is required</div>
</div>
</div>
我试图声明组件无效,如下所示:
invalid = "";
和
invalid: boolean;
但是无论如何,我仍然会收到:
Property 'invalid' does not exist on type 'string'.
答案 0 :(得分:0)
错误并未使您指向丢失的变量。它告诉您字符串类型的变量没有属性invalid
的值。从代码段来看,category.invalid