typescript - Ionic 2 / Angular 2 | Diagnostics registerBluetoothStateChangeHandler -> update view -


i'm trying use diagnostics plugin in ionic 2 application. i'm trying listen bluetooth state changes. based on change want update view.

the handler working fine, issue variables updated in function aren't updated in view.

i can't figure out cause of problem, i've been searching , found answers observables, @input(), , many more haven't been able solve it.

also documentation of diagnostics plugin (https://github.com/dpa99c/cordova-diagnostic-plugin) minimal. haven't been able make of that.

an example of code:

import { diagnostic } 'ionic-native'; import { platform } 'ionic-angular';  export class testpage {     @input()     bluetoothenabled: boolean = false;      constructor(public platform: platform) {          this.platform = platform;          this.platform.ready().then(() => {              diagnostic.registerbluetoothstatechangehandler(function(state) {                  if(state == 'powered_on') {                       this.bluetoothenabled = true;                 } else {                      this.bluetoothenabled = false;                 }             });         });     } } 

in view have button similar this:

<button [color]="bluetoothenabled ? 'secondary' : 'danger'">test</button> 

obviously i'm new angular 2, still trying head around it. think lot of people struggling these issues, since angular 2 new there aren't many examples out there.

i hope guys can me out, in advance!


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -