@arronar wrote:
Hi all!
I’m curious why a part of my view doesn’t update after the model has been changed. So my view is using the
async
pipe to subscribe into an observable and creates a list. If this observable is got updated then for some reason, the view doesn’t updated.Here is the example of my view:
<ng-container *ngFor="let device of devices | async"> <ion-item *ngIf="device.name"> <ion-label> <h2>{{device.name}}</h2> <h3>{{device.address}}</h3> <p>{{device.rssi}}</p> </ion-label> <ion-button *ngIf="!device.isConnected" size="small" color="primary" item-right (click)="connect(device.address)">Connect <ion-icon name="bluetooth"></ion-icon></ion-button> <ion-button *ngIf="device.isConnected" size="small" color="success" item-right >Connected</ion-button> </ion-item> </ng-container>
and here is the code that updates the
devices
observable inside a service:private setConnected(address, isConnected: boolean) { const currentValue = this.devices$.getValue(); const newValue = currentValue.map( e => { if (e.address === address) { e.isConnected = isConnected; } return e; }); this.devices$.next(newValue); }
Is this due to the lack of ngZone or am I doing something wrong? If it due to ngZone, where am I suppose to use it? In the view or in the service ? Can you give me an example?
Posts: 1
Participants: 1