Javascript angular ngModel在浏览器控制台中生成的错误太多
我正在做一个简单的积垢页面。当我输入错误代码时,我的浏览器控制台错误计数突然上升。为什么?实际上它只有一两个错误 19590个错误,1个警告 .ts: .html:Javascript angular ngModel在浏览器控制台中生成的错误太多,javascript,angular,Javascript,Angular,我正在做一个简单的积垢页面。当我输入错误代码时,我的浏览器控制台错误计数突然上升。为什么?实际上它只有一两个错误 19590个错误,1个警告 .ts: .html: <select class="form-control m-input" name="kategori" id="kategori" [(ngModel)]="document.id" > <option disabled [ngValue]="null">Please S
<select class="form-control m-input"
name="kategori" id="kategori" [(ngModel)]="document.id" >
<option disabled [ngValue]="null">Please Select</option>
</select>
请选择
如果我删除[(ngModel)]=“document.id”错误已经消失,并且只有一个错误。我能做什么
注意:我没有给这个问题提供新的实例“document”好的,所以您需要在组件中使用document变量,您需要像下面那样注入它:
import {DOCUMENT} from '@angular/common';
export class YourComponent {
constructor(@Inject(DOCUMENT) private document: any){
console.log(this.document.id);
}
}
之后,您可以在
ngModel
中使用它,您必须首先像这样初始化文档
类
document: Document = new Document();
请参见此处的stackblitz演示:
当我输入错误代码时,我的浏览器控制台错误计数突然上升。为什么?
Dependency@RameshRajendranDependency是什么意思每次运行更改检测时模板(html)中出现错误时,将重新提交模板并再次导致错误。是否初始化文档对象?另外,您得到的错误是什么?可能是您有其他东西触发更改检测。在这个stackblitz中,当错误发生时,页面上没有任何内容。事实上,我不想数百次出现相同的错误。我告诉过你,这是项目中的更改检测:)。是的,我正在动态打开页面,并且在我的项目中使用changedetector NgaftViewInit。->this.cdRef.detectChanges();
document: Document = new Document();