[英]Compilation error-Property value does not exist on type Element in angular 8
[英]While coding a delete function in CRUD Angular app, why does a compilation error show property _id doesn't exist in array?
在使用Angular的MEAN应用程序上工作时,如果我使用this
关键字直接在数组上工作,则编译器似乎显示错误。
例如,下面的代码返回编译错误。
deleteTodo(todo) {
this.todoService.deleteTodo(todo._id)
.map(res => res.json)
.subscribe( data => {
for(var i=0 ; i < this.todos.length; i++) {
if(this.todos[i]._id == todo._id)
this.todos.splice(i, 1);
}
});
}
错误提示_id未在Todo类型中定义
Todo.ts
export class Todo{
text: string;
isCompleted: boolean;
}
todos.component.ts的代码在此处链接: https : //github.com/ajayns/angular-projects/blob/master/mean-todo/src/app/todos/todos.component.ts
export class Todo{
_id: string;
text: string;
isCompleted: boolean;
}
您错过了_id属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.