gpt4 book ai didi

javascript - angular2 @Input EventEmitter 更新 View

转载 作者:太空宇宙 更新时间:2023-11-04 16:32:14 25 4
gpt4 key购买 nike

我正在尝试制作一个简单的网格组件,但在发出事件后更新 View 时遇到问题!请解释谁知道,为什么更新简单组件后, View 不重新渲染?这段代码有什么问题吗?

export class GridComponent implements OnInit {
@Input() resource: any [];
@Output() saveModel = new EventEmitter();
@Output() deleteModel = new EventEmitter();
attributes: any[];
isUpdating: boolean = false;
updatingID: number;

constructor() {}

ngOnInit() {
this.attributes = Object.keys(this.resource[0]);
}

toggleUpdate(id, flag = true) {
this.isUpdating = !this.isUpdating;
this.updatingID = flag ? id : undefined;
}

destroy(id) {
this.deleteModel.emit(id);
}

save(model) {
this.saveModel.emit(model);
this.toggleUpdate(model.id, false);
}

cancel(id) {
this.toggleUpdate(id, false);
}

}

完整示例在这里 https://plnkr.co/edit/InxsHu9GwCtMplYoocsS?p=preview

最佳答案

父组件和子组件中的resource数据已正确更新,只是表单不显示更新。

我认为您需要更改 values 管道以仅返回键而不返回值,然后使用带有键的 *ngFor 变量访问值直接在 View 中的值。

关于javascript - angular2 @Input EventEmitter 更新 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39699704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com