ngOnChanges只调用一次但不在更新数组

时间:2016-11-16 23:29:59

标签: angular

我有两个子组件的父组件。

最初,父级通过ajax将数据加载传递给子组件。

但是当我发送请求有效负载 - 通过事件触发器 - 从child1发送到父级并且父级正在加载数据以更新子级2时,则永远不会触发child2.ngOnChanges方法!

PARENT

 gradingKeyModel1: IGradingKeyModel;
  gradingKeys: any[];
  @Input() gradingKeyModel: IGradingKeyModel


  ngOnChanges(...args: any[])
  {
    let currentValue = args[0].gradingKeyModel.currentValue;

    this.gradingKeyModel1 = currentValue;
    this.gradingKeys = currentValue.gradingKeys; // does updates CHILD1 initially successfully !!!!!!!!!!!!!!!!!!1
  }

  gradingKeyUpdate(request: GradingKeyRequest) {
    this.testsService.getGradingKeyPairs(request).subscribe(gradings => {
      this.gradingKeys = gradings; // does NOT update CHILD1 input field at least the ngOnChanges method is never called.
    });
  }

CHILD1

  groupedGradingKeys: any[];
  @Input() gradingKeys: any[];

  ngOnChanges(...args: any[]) 
  {
    let gradingKeys = args[0].gradingKeys.currentValue;

    if (gradingKeys) {
      let query = // do stuff

      this.groupedGradingKeys = query;
    }
  }

为什么没有使用更新按钮调用ngOnChanges,这意味着它最初工作一次后?? !!

0 个答案:

没有答案