Javascript angular2@Input EventEmitter更新视图

Javascript angular2@Input EventEmitter更新视图,javascript,forms,angular,Javascript,Forms,Angular,我试图制作一个简单的网格组件,但在发出事件后更新视图时遇到了问题! 请解释谁知道,为什么在更新简单组件后,视图不会重新呈现?这个代码有什么问题 export class GridComponent implements OnInit { @Input() resource: any []; @Output() saveModel = new EventEmitter(); @Output() deleteModel = new EventEmitter(); attributes

我试图制作一个简单的网格组件,但在发出事件后更新视图时遇到了问题! 请解释谁知道,为什么在更新简单组件后,视图不会重新呈现?这个代码有什么问题

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);
  }

}

这里的完整示例

父组件和子组件中的
资源
数据已正确更新,只是表单未显示更新

我认为您需要更改
管道以仅返回键而不返回值,然后使用
*ngFor
变量和键访问值,以直接在视图中获取值。

编辑: 甘特·泽克鲍尔,谢谢你节省了我的时间

我认为您需要更改values管道,以仅返回键,而不返回值,然后使用*ngFor变量和键访问值,以直接在视图中获取值


这是罪恶的根源

预期的行为是什么?重现问题需要哪些步骤?我有一个对象数组和网格组件,只有*ngFor这个数组上的指令循环,第二个*ngFor带有自定义管道的对象上的循环。GridComponent具有@Output destroy和save。单击“更新”按钮时,“替代数据”组件显示具有模型当前值的输入,并将其与模型绑定。Save方法触发器事件和父组件侦听该事件,并正确传递新数据,接下来我将替换为新数组,但在屏幕上显示相同的数据。我尝试实现ngOnChanges事件并分配给this.resource=values.resource.currentValue,但未成功