Ionic View content is not updating

Hello guys, i am developing an Ionic 2 app with the IBeacon plugin. In my View/Class i am searching for beacons and i am listening for the ibeacon events (i subscribed to it) to get all discovered beacons and with ngFor i print out all discovered beacons on the view.
My Problem here is that the View is not automatically refreshing its content. The View only refresh its content when I press another button or when i interact with the view.

How can I solve this problem?
Many thanks in advance!

Hi @aliii_i,

Are you updating the scope variable in didRangeBeaconsInRegion() ?

Also I have a question too. I am working on the same app as you but I can’t discover my beacons, I am getting empty beacons array, can you please help me? See the screenshot

the ibeacon will not be trigger angular 2 change detection i think.
Maybe you can send us some code.

But you can try to inject the changeDectorRef in your component and call the markForCheck method to trigger changedetection:

https://angular.io/docs/js/latest/api/core/index/ChangeDetectorRef-class.html#!#markForCheck-anchor

@MuzammilVerisiani: I had the same problem at the beginning. The Problem here is Android 6. After the Installation of the app there should be a permission request for the location, but the request was skipped by the plugin. You have to set the location-permission for the app manually in the settings of your device (settings -> apps). Then I think it should work.

@bengtler @MuzammilVerisiani :
My code currently looks like this:
this.platform.ready().then(() => { let delegate = this.beaconService.getDelegate(); delegate.didRangeBeaconsInRegion().subscribe( (data) => { for(var i = 0; i < data.beacons.length; i++){ //this.beacons.push(data.beacons[i]); this.beacondata.list.push(data.beacons[i]) } }, (error) => { alert(error) } ) })

I will give it a try with the changeDectorRef.
But if you have other suggestions after seeing my code please tell me :slight_smile:
Thanks

Hi @aliii_i,

Thanks for the reply, yes it was a permission issue, I have already resolved it :slight_smile: and its working perfectly.

Your code is very similar to mine. @bengtler is right we have to use changeDectorRef to update the view.

Thanks

@aliii_i @bengtler,

I just implemented changeDectorRef and it worked like a charm! :slight_smile:

Thank you

1 Like