Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 数组-更改不会传播到子组件_Angular_Typescript - Fatal编程技术网

Angular 数组-更改不会传播到子组件

Angular 数组-更改不会传播到子组件,angular,typescript,Angular,Typescript,家长: <div id="join-container"> <join-chain id="my-join-chain" [selectedColumn]="selectedColumn" (updatedStatements)=onUpdatedStatements($event)> </join-chain> <tile-canvas id="my-tile-canvas" [mystate

家长:

<div id="join-container">
  <join-chain 
    id="my-join-chain" 
    [selectedColumn]="selectedColumn"
    (updatedStatements)=onUpdatedStatements($event)>
  </join-chain>
  <tile-canvas 
    id="my-tile-canvas" 
    [mystatements]="theStatements"
    (selectedColumn)="onSelectedColumn($event)">
  </tile-canvas>
</div>
孩子:

...
  mappings: Mapping[] = []
  @Input() set mystatements(someStatements: Relational.JoinStatement[] | undefined) {
    console.log(">> tile canvas interceptor")
    console.log(someStatements)
    if (someStatements !== undefined) {
      let idsFromStatements = someStatements
        .map(statement => [statement.leftTile, statement.rightTile])
        .filter(mapping => (mapping[0] !== undefined) && (mapping[1] !== undefined)) as ([Relational.tileId, Relational.tileId])[]
      this.mappings = idsFromStatements.map(ids => new Mapping(ids))
    }
  }
当我玩应用程序时,我看到从步骤加入触发的消息
。 另一方面,
>tile canvas interceptor
只发生一次,发生在从步骤加入启动的第一个
之后

我读了好几篇文章,发现有一个类似的模式,那就是每次都会触发“拦截器”

onUpdatedStatements(statements: Relational.JoinStatement[]) {
this.theStatements = statements;
console.log(">> fired from step-joining")
console.log(this.theStatements)
}

If语句具有与此相同的引用和值。更改后的语句将不会从
控制台在子组件中激发。log
我看到
语句更改。想知道我们有一个数组这一事实是否会把事情搞砸。检查这个答案是的,我现在理解这个问题了。为了触发更改,您将如何处理对象数组?谢谢@NoIdeaHowToFixThis-您可以尝试
this.theStatements=statements.slice(0)。这将创建源数组的副本。请考虑创建StasBLITIZ。
onUpdatedStatements(statements: Relational.JoinStatement[]) {
this.theStatements = statements;
console.log(">> fired from step-joining")
console.log(this.theStatements)
}