[英]angular2 @Input EventEmitter update view
iam trying to make a simple grid component and i have a trouble with updating view after emitting event !我正在尝试制作一个简单的网格组件,但在发出事件后更新视图时遇到了麻烦! Please explain who knows, why after updating simple component, view do not re-rendered ?
请谁知道,为什么更新简单组件后,视图不重新渲染? whats wrong with this code ?
这段代码有什么问题?
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);
}
}
Full example here https://plnkr.co/edit/InxsHu9GwCtMplYoocsS?p=preview完整示例在这里https://plnkr.co/edit/InxsHu9GwCtMplYoocsS?p=preview
The resource
data is updated properly in parent and child components, just the form doesn't show the update. resource
数据在父组件和子组件中正确更新,只是表单不显示更新。
I think you need to change the values
pipe to only return the keys but not the values and then access the values using the *ngFor
variables with the keys to get the values in the view directly.我认为您需要更改
values
管道以仅返回键而不返回值,然后使用带有键的*ngFor
变量访问值以直接获取视图中的值。
EDITED: Günter Zöchbauer, thank you saved my time !编辑: Günter Zöchbauer,谢谢你节省了我的时间!
I think you need to change the values pipe to only return the keys but not the values and then access the values using the *ngFor variables with the keys to get the values in the view directly.我认为您需要更改值管道以仅返回键而不返回值,然后使用带有键的 *ngFor 变量访问值以直接获取视图中的值。
this was root of evil这是邪恶的根源
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.