如果在Angular 7中更新和删除功能无法正常工作,可以尝试以下解决方法:
updateItem(item: any) {
// 更新逻辑
}
deleteItem(item: any) {
// 删除逻辑
}
updateItem(item: any) {
// 更新逻辑
item.name = 'New Name';
}
deleteItem(item: any) {
// 删除逻辑
const index = this.items.indexOf(item);
if (index !== -1) {
this.items.splice(index, 1);
}
}
import { HttpClient } from '@angular/common/http';
constructor(private http: HttpClient) {}
updateItem(item: any) {
// 更新逻辑
this.http.put('/api/items/' + item.id, item).subscribe(response => {
console.log(response);
});
}
deleteItem(item: any) {
// 删除逻辑
this.http.delete('/api/items/' + item.id).subscribe(response => {
console.log(response);
const index = this.items.indexOf(item);
if (index !== -1) {
this.items.splice(index, 1);
}
});
}
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
FormsModule
],
// ...
})
export class AppModule { }
通过检查以上方面,应该能够解决Angular 7中更新和删除功能无法正常工作的问题。