Javascript 错误TS7006:参数';项目';隐式具有';任何';类型
我很难确定这个错误的根源。以下是来自终端的完整错误代码:Javascript 错误TS7006:参数';项目';隐式具有';任何';类型,javascript,angular,typescript,Javascript,Angular,Typescript,我很难确定这个错误的根源。以下是来自终端的完整错误代码: Error: src/app/box/show-box/show-box.component.ts:33:13 - error TS7006: Parameter 'item' implicitly has an 'any' type. 33 editClick(item){ 这是我对应的show-box.component.ts文件: import { Component, OnInit } from '@angular/cor
Error: src/app/box/show-box/show-box.component.ts:33:13 - error TS7006: Parameter 'item' implicitly has an 'any' type.
33 editClick(item){
这是我对应的show-box.component.ts文件:
import { Component, OnInit } from '@angular/core';
import { SharedService } from 'src/app/shared.service';
@Component({
selector: 'app-show-box',
templateUrl: './show-box.component.html',
styleUrls: ['./show-box.component.css']
})
export class ShowBoxComponent implements OnInit {
constructor(private service:SharedService) { }
BoxList:any=[];
ModalTitle:string;
ActivateAddEditBoxComp:boolean=false;
box:any;
ngOnInit(): void {
this.refreshBoxList();
}
addClick(){
this.box={
BoxId:0,
BoxName1:"",
BoxName2:"",
}
this.ModalTitle="Add Box";
this.ActivateAddEditBoxComp=true;
}
editClick(item){
this.box=item;
this.ModalTitle="Edit Box";
this.ActivateAddEditBoxComp=true;
}
closeClick(){
this.ActivateAddEditBoxComp=false;
this.refreshUserList();
}
refreshBoxList(){
this.service.getBoxList().subscribe(data=>{
this.BoxList=data;
})
}
}
下面是相关的show-component.box.html文件
<table class="table table striped">
<thead>
<tr>
<th>BoxId</th>
<th>Box 1</th>
<th>Box 2</th>
<th>Options</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let dataItem of BoxList">
<td>{{dataItem.BoxId}}</td>
<td>{{dataItem.Box1}}</td>
<td>{{dataItem.Box2}}</td>
<td>
<button type="button" class="ovwrflow:auto btn btn-primary mr-1" data-toggle="modal"
data-target="#exampleModal"
(click)="editClick(dataItem)"
data-backdrop="static" data-keyboard="false"
>Add Box</button>
<button type="button" class="btn btn-light mr-1">Edit</button>
<button type="button" class="btn btn-light mr-1">Delete</button>
</td>
</tr>
</tbody>
</table>
BoxId
方框1
方框2
选择权
{{dataItem.BoxId}
{{dataItem.Box1}
{{dataItem.Box2}
添加框
编辑
删除
我的问题的根源是什么?我见过其他建议的解决方案,其中人们设置“strict”:false,但这似乎只是一个表面修复,同时仍然提供运行时问题。将类型指定为
任何参数项将解决您的问题
editClick(item: any) {
this.box=item;
this.ModalTitle="Edit Box";
this.ActivateAddEditBoxComp=true;
}
参考:
这是否回答了您的问题?