场景:
工作正常,只是视觉上的一个小问题。但是,当我尝试解决此问题时,该应用程序停止运行。命令行控制台显示以下内容:
src / app / components / pagination / pagination.component.ts(34,11)中的ERROR: 错误TS2339:类型上不存在属性“ forEach” 'NodeListOf'
在chrome中什么也没显示。
问题,正如您所看到的,是我为迭代一些html元素而编写的forEach 。
这是代码的特定片段:
changePage(page:number){
this.fromPag = page*this.pageSize;
let pages:NodeListOf<HTMLElement>;
pages=document.getElementsByName("page");
pages.forEach((page:HTMLElement,index:number)=>{
page.classList.remove("active");
});
let selectedPage = document.getElementById("page" + page);
selectedPage.classList.add("active");
this.onPageChange.emit(this.fromPag);
}
如果您想查看该链接以帮助我,请点击这里。 pagination-demo
依赖关系:
"dependencies": {
"@angular/animations": "^5.2.11",
"@angular/cdk": "^5.2.4",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/material": "^5.2.4",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"angular5-csv": "^0.2.10",
"core-js": "^2.4.1",
"hammerjs": "^2.0.8",
"promise.prototype.finally": "^3.1.0",
"rxjs": "^5.5.6",
"sweetalert2": "^7.26.9",
"zone.js": "^0.8.19"
}
我希望你们能对我有所帮助。
谢谢!