我在页面中创建新输入时始终出现此错误,我不知道为什么,如果没有解决,我会花费大量时间。有人可以帮忙吗?
关注我的HTML:
<div class="form-group"
[ngClass]="{'has-error': (customerForm.get('rating').touched ||
customerForm.get('rating').dirty) &&
!customerForm.get('rating').valid }">
<label class="col-md-2 control-label"
for="ratingId">Rating</label>
<div class="col-md-8">
<input class="form-control"
id="ratingId"
type="number"
formControlName = "rating" />
<span class="help-block" *ngIf="(customerForm.get('rating').touched
|| customerForm.get('rating').dirty) &&
customerForm.get('rating').errors">
<span *ngIf="customerForm.get('rating').errors.range">
Please rate your experience from 1 to 5.
</span>
</span>
</div>
</div>
我已经创建了我的评分&#39;在FormBuilder中:
ngOnInit(): void {
this.customerForm = this.formBuilder.group({
firstName: ['', [Validators.required, Validators.minLength(3)]],
lastName: ['', [Validators.required, Validators.maxLength(50)]],
phone: '',
rating: '',
notification: 'email',
sendCatalog: true
});
}
我还试图在我在HTML中调用(&#39; rating&#39;)名称的所有地方使用&#34;安全导航操作符&#34; ,但是,尝试时,它会在控制台中返回以下错误: 找不到具有名称的控件:&#39; rating&#39;
答案 0 :(得分:0)
我尝试使用与我编写的完全相同的代码创建一个新的解决方案,并且它正常工作。有点尴尬,我应该在我的旧项目中有一个错误,无论如何。