Angular2 changing parent not reflected in child when using array input property

Say we have component A as the parent component and component B as the child component. The child has an entrance what_is_xthat is provided by the parent. Something like that:

For parent:

@Component({
  selector: 'cmp-A',
  directives: [ComponentB],
  template: `<cmp-B [what-is-x]="x"></cmp-B>`
})
export ComponentA {
  public x: any = [1, 2, 3];
  constructor() {
    setTimeout(() => this.x.push(10), 2000);
  }
}

For a child:

// component B with input what_is_x
@Component({
  selector: 'cmp-B',
  template: `{{what_is_x}}`
})
export ComponentB {
  @Input('what-is-x') public what_is_x: any;
}

My question is: if the parent has changed in xany way, is the child updated with the new value? According to the chapter "Communication" in the developer's manual (not yet released); must! but it has not been updated for me, I tried all the Betas so far (0,1,2)

+3
source share
1 answer

. .16, {{what_is_x}} , . . {{myArray}} - 16.


:

, . - doCheck() API doc

@Eric, , , , , – {{what_is_x}} – , (, push()), .

, , @Eric , , .

. ,

<div *ngFor="#item of what_is_x">{{item}}</div>

, , , ( ).

, {{what_is_x | json}}, . ( , JsonPipe stateful, Angular .)

+3

Source: https://habr.com/ru/post/1628618/


All Articles