Encountering an error while working on a MEAN app with Angular, as the compiler does not seem to accept direct manipulation of the array using the this
keyword.
Here is an example where the code triggers a compilation error:
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);
}
});
}
The error message states that _id is not defined in Todo type
Contents of Todo.ts file:
export class Todo{
text: string;
isCompleted: boolean;
}
Refer to the code in todos.component.ts by visiting: https://github.com/ajayns/angular-projects/blob/master/mean-todo/src/app/todos/todos.component.ts