1

I have a service that has a public property declared as follows:

public indiceUsuarios: IndiceUsuario[] = [];

After changing data and doing operations I reload that property with the following method in the same class:

  private reloadIndiceLocal(indiceUsuarios: IndiceUsuario[]): void {
    let self = this;
    self.indiceUsuarios.length = 0;
    self.indiceUsuarios.push(...indiceUsuarios);
  }

I'm injecting this service into another component and referencing that property on the ngOnInit() using the following line this.indiceUsuarios = this.sesionService.indiceUsuarios; (this local property is not initialized before this). I'm then using this local property on this component's view. It shows perfectly fine and is changing when I add elements to the array.

The issue is that if I remove elements from the array they will keep showing (the view is not updating to reflect these changes).

Any ideas?

laurentius
  • 1,093
  • 1
  • 9
  • 20
  • Probably duplicate of https://stackoverflow.com/questions/43397599/angluar2-observable-ui-update-children-in-object-array-force-change/43399138#43399138 and http://stackoverflow.com/questions/36919399/angular-2-view-not-updating-after-model-changes – Ján Halaša Apr 14 '17 at 03:51

1 Answers1

0

Well, In my case it turned out to be that I was relying on a singleton that was poorly written and wasn't acting as a singleton (effectively linking my view to an object with a different instance to the one I was changing). My bad.

laurentius
  • 1,093
  • 1
  • 9
  • 20