{{myArray}} is now updated in view from beta .16

Changed change detection.

Until beta .16, if your view contains {{myArray}}, this binding will not be updated unless you change the reference to the array. For example, if you are push()elements in an array, the view will not be updated to show a new element. The explanation (well, it was), because the array reference has not changed, Angular change detection does not overestimate the binding. This beta.15 plunker demonstrates this behavior.

As of beta .16 (and therefore RC.1), everything is different. The binding {{myArray}}will now be updated even if the array reference has not changed! See RC.1 plunker .

I looked at ChangeLog for beta.16 and I see nothing that could explain this change in behavior (but maybe I missed something). Does anyone know what caused this change, and what else could be affected?

Plunger Code:

@Component({
  selector: 'child',
  template: `<p>child: {{arr}}`
})
export class Child {
  @Input() arr;
}
@Component({
  selector: 'my-app',
  template: `{{title}} <p>parent: {{arr}}
    <button (click)="modifyArray()">modify array</button>
    <child [arr]="arr"></child>`,
  directives: [Child]
})
export class AppComponent {
  title = "Angular 2 beta.15";  // or "Angular 2 RC.1", as appropriate
  arr = 'one two three'.split(' ');
  modifyArray() {
    this.arr.push('another');
    console.log(this.arr);
  }
}
+4
source share
1 answer

I think the code associated with DetectChanges is changing ( ChangeDetector.detectChangesInRecordsInternal beta.15 vs View.detectChangesInternal rc.1). You can see it in the photos.

Beta stack. 15

enter image description here

enter image description here

As you can see, there is a comparison of arrays

stack RC.1

enter image description here

enter image description here

Then we can see the comparison of the expression (string), and they are different. This way angular rc.1 will update the view.

:)

+4

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


All Articles