Ionic 3 : pass provider's variables to ion-input











up vote
0
down vote

favorite












I have this simple provider:



import { Injectable } from "@angular/core";

@Injectable()
export class DevicesService {
public check_string : any;

constructor(){
this.check_string = "Provider enabled";
}

getStatusString() { return this.check_string; }
}


and I am trying to pass that check_string variable to a ion-input in my home.ts:



<strong><ion-input round id="stringstatus" type="text" [(ngModel)]="stringstatus"></ion-input></strong>



import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { DevicesService } from '../../providers/devicefactory/devicefactory';

@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public stateString : string;

constructor(public navCtrl: NavController, private deviceProvider : DevicesService) {
this.stateString = this.deviceProvider.check_string;
//this.stateString = this.deviceProvider.getStatusString();
}

}


I tried both two ways, direct pass variable and getting return function but once I run app it shows blank page.. what I could have missed?



Thanks a lot to all
Cheers!










share|improve this question


























    up vote
    0
    down vote

    favorite












    I have this simple provider:



    import { Injectable } from "@angular/core";

    @Injectable()
    export class DevicesService {
    public check_string : any;

    constructor(){
    this.check_string = "Provider enabled";
    }

    getStatusString() { return this.check_string; }
    }


    and I am trying to pass that check_string variable to a ion-input in my home.ts:



    <strong><ion-input round id="stringstatus" type="text" [(ngModel)]="stringstatus"></ion-input></strong>



    import { Component } from '@angular/core';
    import { NavController } from 'ionic-angular';
    import { DevicesService } from '../../providers/devicefactory/devicefactory';

    @Component({
    selector: 'page-home',
    templateUrl: 'home.html'
    })
    export class HomePage {
    public stateString : string;

    constructor(public navCtrl: NavController, private deviceProvider : DevicesService) {
    this.stateString = this.deviceProvider.check_string;
    //this.stateString = this.deviceProvider.getStatusString();
    }

    }


    I tried both two ways, direct pass variable and getting return function but once I run app it shows blank page.. what I could have missed?



    Thanks a lot to all
    Cheers!










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have this simple provider:



      import { Injectable } from "@angular/core";

      @Injectable()
      export class DevicesService {
      public check_string : any;

      constructor(){
      this.check_string = "Provider enabled";
      }

      getStatusString() { return this.check_string; }
      }


      and I am trying to pass that check_string variable to a ion-input in my home.ts:



      <strong><ion-input round id="stringstatus" type="text" [(ngModel)]="stringstatus"></ion-input></strong>



      import { Component } from '@angular/core';
      import { NavController } from 'ionic-angular';
      import { DevicesService } from '../../providers/devicefactory/devicefactory';

      @Component({
      selector: 'page-home',
      templateUrl: 'home.html'
      })
      export class HomePage {
      public stateString : string;

      constructor(public navCtrl: NavController, private deviceProvider : DevicesService) {
      this.stateString = this.deviceProvider.check_string;
      //this.stateString = this.deviceProvider.getStatusString();
      }

      }


      I tried both two ways, direct pass variable and getting return function but once I run app it shows blank page.. what I could have missed?



      Thanks a lot to all
      Cheers!










      share|improve this question













      I have this simple provider:



      import { Injectable } from "@angular/core";

      @Injectable()
      export class DevicesService {
      public check_string : any;

      constructor(){
      this.check_string = "Provider enabled";
      }

      getStatusString() { return this.check_string; }
      }


      and I am trying to pass that check_string variable to a ion-input in my home.ts:



      <strong><ion-input round id="stringstatus" type="text" [(ngModel)]="stringstatus"></ion-input></strong>



      import { Component } from '@angular/core';
      import { NavController } from 'ionic-angular';
      import { DevicesService } from '../../providers/devicefactory/devicefactory';

      @Component({
      selector: 'page-home',
      templateUrl: 'home.html'
      })
      export class HomePage {
      public stateString : string;

      constructor(public navCtrl: NavController, private deviceProvider : DevicesService) {
      this.stateString = this.deviceProvider.check_string;
      //this.stateString = this.deviceProvider.getStatusString();
      }

      }


      I tried both two ways, direct pass variable and getting return function but once I run app it shows blank page.. what I could have missed?



      Thanks a lot to all
      Cheers!







      ionic-framework ionic3






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 6:07









      Luigino

      165213




      165213
























          3 Answers
          3






          active

          oldest

          votes

















          up vote
          0
          down vote













          Try using deviceProvider.getStatusString(). Without using this in constructor;



          constructor(public navCtrl: NavController, private deviceProvider : DevicesService) {
          this.stateString = deviceProvider.getStatusString();
          }





          share|improve this answer





















          • I put as you said, Rameez, obtaining this:
            – Luigino
            Nov 20 at 17:46


















          up vote
          0
          down vote













          You can directly set it in your ngModel :



          [(ngModel)]="deviceProvider.check_string"


          or



          [(ngModel)]="deviceProvider.getStatusString()"





          share|improve this answer




























            up vote
            0
            down vote













            Hello Rameez and saperlipopette,



            I tried as both of you obtaining this:



            devicefactory.ts



            import { Injectable } from "@angular/core";
            //import { BluetoothLE } from '@ionic-native/bluetooth-le';

            @Injectable()
            export class DevicesService {
            public ble_status : boolean;
            public check_string : any;

            // public BLE : BluetoothLE
            constructor(){
            this.ble_status = false;
            //this.BLE.initialize();
            //this.BLE.isEnabled().then(result => { this.ble_status = result.isEnabled; });
            this.check_string = "Provider enabled";
            }

            getStatus() { return this.ble_status; }
            getStatusString() { return this.check_string; }

            enableBLE() {
            //if (this.ble_status) this.BLE.enable(); else this.BLE.disable();
            if (this.ble_status) this.check_string = "Provider enabled"; else this.check_string = "Provider disabled";
            }
            }


            app.module.ts



            import { NgModule, ErrorHandler } from '@angular/core';
            import { BrowserModule } from '@angular/platform-browser';
            import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
            import { HoergerateApp } from './app.component';

            import { AboutPage } from '../pages/about/about';
            import { ContactPage } from '../pages/contact/contact';
            import { HomePage } from '../pages/home/home';
            import { TabsPage } from '../pages/tabs/tabs';

            import { StatusBar } from '@ionic-native/status-bar';
            import { SplashScreen } from '@ionic-native/splash-screen';
            import { SettingsPage } from '../pages/settings/settings';
            import { DevicesService } from '../providers/devicefactory/devicefactory';


            @NgModule({
            declarations: [
            HoergerateApp,
            AboutPage,
            SettingsPage,
            ContactPage,
            HomePage,
            TabsPage
            ],
            imports: [
            BrowserModule,
            IonicModule.forRoot(HoergerateApp)
            ],
            bootstrap: [IonicApp],
            entryComponents: [
            HoergerateApp,
            AboutPage,
            SettingsPage,
            ContactPage,
            HomePage,
            TabsPage
            ],
            providers: [
            StatusBar,
            SplashScreen,
            DevicesService,
            {provide: ErrorHandler, useClass: IonicErrorHandler}
            ]
            })
            export class AppModule {

            }


            home.html



            <ion-header>
            <ion-navbar>
            <ion-title>Home</ion-title>
            </ion-navbar>
            </ion-header>

            <ion-content padding>
            <h2>Welcome to Ionic!</h2>
            <p>
            This starter project comes with simple tabs-based layout for apps
            that are going to primarily use a Tabbed UI.
            </p>
            <p>
            Take a look at the <code>src/pages/</code> directory to add or change tabs,
            update any existing page or create new pages.
            </p>
            <p>
            Check bluetooth status:<br>
            <strong><ion-input round id="ble_state" type="text" [(ngModel)]="ble_state"></ion-input></strong>
            </p>
            </ion-content>


            home.ts



            import { Component } from '@angular/core';
            import { NavController } from 'ionic-angular';
            import { DevicesService } from '../../providers/devicefactory/devicefactory';

            @Component({
            selector: 'page-home',
            templateUrl: 'home.html'
            })
            export class HomePage {
            public ble_state : string;

            constructor(public navCtrl: NavController, public deviceProvider : DevicesService) {
            //this.ble_state = ( this.deviceService.ble_status ? "Bluetooth is enabled" : "BLuetooth is disabled" );

            //this.ble_state = deviceProvider.check_string;
            this.ble_state = deviceProvider.getStatusString();
            }

            }


            Before I put also directly in [(ngModel)] but it goes for blank page..... I think it's related something about passing variables maybe because if I comment that:



            this.ble_state = deviceProvider.getStatusString();


            the app appears working...
            Maybe it's related about ionic and cordova installation platforms or dependencies even if it didn't reported any errors during compilation?



            Thanks






            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387159%2fionic-3-pass-providers-variables-to-ion-input%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote













              Try using deviceProvider.getStatusString(). Without using this in constructor;



              constructor(public navCtrl: NavController, private deviceProvider : DevicesService) {
              this.stateString = deviceProvider.getStatusString();
              }





              share|improve this answer





















              • I put as you said, Rameez, obtaining this:
                – Luigino
                Nov 20 at 17:46















              up vote
              0
              down vote













              Try using deviceProvider.getStatusString(). Without using this in constructor;



              constructor(public navCtrl: NavController, private deviceProvider : DevicesService) {
              this.stateString = deviceProvider.getStatusString();
              }





              share|improve this answer





















              • I put as you said, Rameez, obtaining this:
                – Luigino
                Nov 20 at 17:46













              up vote
              0
              down vote










              up vote
              0
              down vote









              Try using deviceProvider.getStatusString(). Without using this in constructor;



              constructor(public navCtrl: NavController, private deviceProvider : DevicesService) {
              this.stateString = deviceProvider.getStatusString();
              }





              share|improve this answer












              Try using deviceProvider.getStatusString(). Without using this in constructor;



              constructor(public navCtrl: NavController, private deviceProvider : DevicesService) {
              this.stateString = deviceProvider.getStatusString();
              }






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 20 at 8:04









              Rameez Raja

              12710




              12710












              • I put as you said, Rameez, obtaining this:
                – Luigino
                Nov 20 at 17:46


















              • I put as you said, Rameez, obtaining this:
                – Luigino
                Nov 20 at 17:46
















              I put as you said, Rameez, obtaining this:
              – Luigino
              Nov 20 at 17:46




              I put as you said, Rameez, obtaining this:
              – Luigino
              Nov 20 at 17:46












              up vote
              0
              down vote













              You can directly set it in your ngModel :



              [(ngModel)]="deviceProvider.check_string"


              or



              [(ngModel)]="deviceProvider.getStatusString()"





              share|improve this answer

























                up vote
                0
                down vote













                You can directly set it in your ngModel :



                [(ngModel)]="deviceProvider.check_string"


                or



                [(ngModel)]="deviceProvider.getStatusString()"





                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  You can directly set it in your ngModel :



                  [(ngModel)]="deviceProvider.check_string"


                  or



                  [(ngModel)]="deviceProvider.getStatusString()"





                  share|improve this answer












                  You can directly set it in your ngModel :



                  [(ngModel)]="deviceProvider.check_string"


                  or



                  [(ngModel)]="deviceProvider.getStatusString()"






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 20 at 15:23









                  saperlipopette

                  559316




                  559316






















                      up vote
                      0
                      down vote













                      Hello Rameez and saperlipopette,



                      I tried as both of you obtaining this:



                      devicefactory.ts



                      import { Injectable } from "@angular/core";
                      //import { BluetoothLE } from '@ionic-native/bluetooth-le';

                      @Injectable()
                      export class DevicesService {
                      public ble_status : boolean;
                      public check_string : any;

                      // public BLE : BluetoothLE
                      constructor(){
                      this.ble_status = false;
                      //this.BLE.initialize();
                      //this.BLE.isEnabled().then(result => { this.ble_status = result.isEnabled; });
                      this.check_string = "Provider enabled";
                      }

                      getStatus() { return this.ble_status; }
                      getStatusString() { return this.check_string; }

                      enableBLE() {
                      //if (this.ble_status) this.BLE.enable(); else this.BLE.disable();
                      if (this.ble_status) this.check_string = "Provider enabled"; else this.check_string = "Provider disabled";
                      }
                      }


                      app.module.ts



                      import { NgModule, ErrorHandler } from '@angular/core';
                      import { BrowserModule } from '@angular/platform-browser';
                      import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
                      import { HoergerateApp } from './app.component';

                      import { AboutPage } from '../pages/about/about';
                      import { ContactPage } from '../pages/contact/contact';
                      import { HomePage } from '../pages/home/home';
                      import { TabsPage } from '../pages/tabs/tabs';

                      import { StatusBar } from '@ionic-native/status-bar';
                      import { SplashScreen } from '@ionic-native/splash-screen';
                      import { SettingsPage } from '../pages/settings/settings';
                      import { DevicesService } from '../providers/devicefactory/devicefactory';


                      @NgModule({
                      declarations: [
                      HoergerateApp,
                      AboutPage,
                      SettingsPage,
                      ContactPage,
                      HomePage,
                      TabsPage
                      ],
                      imports: [
                      BrowserModule,
                      IonicModule.forRoot(HoergerateApp)
                      ],
                      bootstrap: [IonicApp],
                      entryComponents: [
                      HoergerateApp,
                      AboutPage,
                      SettingsPage,
                      ContactPage,
                      HomePage,
                      TabsPage
                      ],
                      providers: [
                      StatusBar,
                      SplashScreen,
                      DevicesService,
                      {provide: ErrorHandler, useClass: IonicErrorHandler}
                      ]
                      })
                      export class AppModule {

                      }


                      home.html



                      <ion-header>
                      <ion-navbar>
                      <ion-title>Home</ion-title>
                      </ion-navbar>
                      </ion-header>

                      <ion-content padding>
                      <h2>Welcome to Ionic!</h2>
                      <p>
                      This starter project comes with simple tabs-based layout for apps
                      that are going to primarily use a Tabbed UI.
                      </p>
                      <p>
                      Take a look at the <code>src/pages/</code> directory to add or change tabs,
                      update any existing page or create new pages.
                      </p>
                      <p>
                      Check bluetooth status:<br>
                      <strong><ion-input round id="ble_state" type="text" [(ngModel)]="ble_state"></ion-input></strong>
                      </p>
                      </ion-content>


                      home.ts



                      import { Component } from '@angular/core';
                      import { NavController } from 'ionic-angular';
                      import { DevicesService } from '../../providers/devicefactory/devicefactory';

                      @Component({
                      selector: 'page-home',
                      templateUrl: 'home.html'
                      })
                      export class HomePage {
                      public ble_state : string;

                      constructor(public navCtrl: NavController, public deviceProvider : DevicesService) {
                      //this.ble_state = ( this.deviceService.ble_status ? "Bluetooth is enabled" : "BLuetooth is disabled" );

                      //this.ble_state = deviceProvider.check_string;
                      this.ble_state = deviceProvider.getStatusString();
                      }

                      }


                      Before I put also directly in [(ngModel)] but it goes for blank page..... I think it's related something about passing variables maybe because if I comment that:



                      this.ble_state = deviceProvider.getStatusString();


                      the app appears working...
                      Maybe it's related about ionic and cordova installation platforms or dependencies even if it didn't reported any errors during compilation?



                      Thanks






                      share|improve this answer

























                        up vote
                        0
                        down vote













                        Hello Rameez and saperlipopette,



                        I tried as both of you obtaining this:



                        devicefactory.ts



                        import { Injectable } from "@angular/core";
                        //import { BluetoothLE } from '@ionic-native/bluetooth-le';

                        @Injectable()
                        export class DevicesService {
                        public ble_status : boolean;
                        public check_string : any;

                        // public BLE : BluetoothLE
                        constructor(){
                        this.ble_status = false;
                        //this.BLE.initialize();
                        //this.BLE.isEnabled().then(result => { this.ble_status = result.isEnabled; });
                        this.check_string = "Provider enabled";
                        }

                        getStatus() { return this.ble_status; }
                        getStatusString() { return this.check_string; }

                        enableBLE() {
                        //if (this.ble_status) this.BLE.enable(); else this.BLE.disable();
                        if (this.ble_status) this.check_string = "Provider enabled"; else this.check_string = "Provider disabled";
                        }
                        }


                        app.module.ts



                        import { NgModule, ErrorHandler } from '@angular/core';
                        import { BrowserModule } from '@angular/platform-browser';
                        import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
                        import { HoergerateApp } from './app.component';

                        import { AboutPage } from '../pages/about/about';
                        import { ContactPage } from '../pages/contact/contact';
                        import { HomePage } from '../pages/home/home';
                        import { TabsPage } from '../pages/tabs/tabs';

                        import { StatusBar } from '@ionic-native/status-bar';
                        import { SplashScreen } from '@ionic-native/splash-screen';
                        import { SettingsPage } from '../pages/settings/settings';
                        import { DevicesService } from '../providers/devicefactory/devicefactory';


                        @NgModule({
                        declarations: [
                        HoergerateApp,
                        AboutPage,
                        SettingsPage,
                        ContactPage,
                        HomePage,
                        TabsPage
                        ],
                        imports: [
                        BrowserModule,
                        IonicModule.forRoot(HoergerateApp)
                        ],
                        bootstrap: [IonicApp],
                        entryComponents: [
                        HoergerateApp,
                        AboutPage,
                        SettingsPage,
                        ContactPage,
                        HomePage,
                        TabsPage
                        ],
                        providers: [
                        StatusBar,
                        SplashScreen,
                        DevicesService,
                        {provide: ErrorHandler, useClass: IonicErrorHandler}
                        ]
                        })
                        export class AppModule {

                        }


                        home.html



                        <ion-header>
                        <ion-navbar>
                        <ion-title>Home</ion-title>
                        </ion-navbar>
                        </ion-header>

                        <ion-content padding>
                        <h2>Welcome to Ionic!</h2>
                        <p>
                        This starter project comes with simple tabs-based layout for apps
                        that are going to primarily use a Tabbed UI.
                        </p>
                        <p>
                        Take a look at the <code>src/pages/</code> directory to add or change tabs,
                        update any existing page or create new pages.
                        </p>
                        <p>
                        Check bluetooth status:<br>
                        <strong><ion-input round id="ble_state" type="text" [(ngModel)]="ble_state"></ion-input></strong>
                        </p>
                        </ion-content>


                        home.ts



                        import { Component } from '@angular/core';
                        import { NavController } from 'ionic-angular';
                        import { DevicesService } from '../../providers/devicefactory/devicefactory';

                        @Component({
                        selector: 'page-home',
                        templateUrl: 'home.html'
                        })
                        export class HomePage {
                        public ble_state : string;

                        constructor(public navCtrl: NavController, public deviceProvider : DevicesService) {
                        //this.ble_state = ( this.deviceService.ble_status ? "Bluetooth is enabled" : "BLuetooth is disabled" );

                        //this.ble_state = deviceProvider.check_string;
                        this.ble_state = deviceProvider.getStatusString();
                        }

                        }


                        Before I put also directly in [(ngModel)] but it goes for blank page..... I think it's related something about passing variables maybe because if I comment that:



                        this.ble_state = deviceProvider.getStatusString();


                        the app appears working...
                        Maybe it's related about ionic and cordova installation platforms or dependencies even if it didn't reported any errors during compilation?



                        Thanks






                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          Hello Rameez and saperlipopette,



                          I tried as both of you obtaining this:



                          devicefactory.ts



                          import { Injectable } from "@angular/core";
                          //import { BluetoothLE } from '@ionic-native/bluetooth-le';

                          @Injectable()
                          export class DevicesService {
                          public ble_status : boolean;
                          public check_string : any;

                          // public BLE : BluetoothLE
                          constructor(){
                          this.ble_status = false;
                          //this.BLE.initialize();
                          //this.BLE.isEnabled().then(result => { this.ble_status = result.isEnabled; });
                          this.check_string = "Provider enabled";
                          }

                          getStatus() { return this.ble_status; }
                          getStatusString() { return this.check_string; }

                          enableBLE() {
                          //if (this.ble_status) this.BLE.enable(); else this.BLE.disable();
                          if (this.ble_status) this.check_string = "Provider enabled"; else this.check_string = "Provider disabled";
                          }
                          }


                          app.module.ts



                          import { NgModule, ErrorHandler } from '@angular/core';
                          import { BrowserModule } from '@angular/platform-browser';
                          import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
                          import { HoergerateApp } from './app.component';

                          import { AboutPage } from '../pages/about/about';
                          import { ContactPage } from '../pages/contact/contact';
                          import { HomePage } from '../pages/home/home';
                          import { TabsPage } from '../pages/tabs/tabs';

                          import { StatusBar } from '@ionic-native/status-bar';
                          import { SplashScreen } from '@ionic-native/splash-screen';
                          import { SettingsPage } from '../pages/settings/settings';
                          import { DevicesService } from '../providers/devicefactory/devicefactory';


                          @NgModule({
                          declarations: [
                          HoergerateApp,
                          AboutPage,
                          SettingsPage,
                          ContactPage,
                          HomePage,
                          TabsPage
                          ],
                          imports: [
                          BrowserModule,
                          IonicModule.forRoot(HoergerateApp)
                          ],
                          bootstrap: [IonicApp],
                          entryComponents: [
                          HoergerateApp,
                          AboutPage,
                          SettingsPage,
                          ContactPage,
                          HomePage,
                          TabsPage
                          ],
                          providers: [
                          StatusBar,
                          SplashScreen,
                          DevicesService,
                          {provide: ErrorHandler, useClass: IonicErrorHandler}
                          ]
                          })
                          export class AppModule {

                          }


                          home.html



                          <ion-header>
                          <ion-navbar>
                          <ion-title>Home</ion-title>
                          </ion-navbar>
                          </ion-header>

                          <ion-content padding>
                          <h2>Welcome to Ionic!</h2>
                          <p>
                          This starter project comes with simple tabs-based layout for apps
                          that are going to primarily use a Tabbed UI.
                          </p>
                          <p>
                          Take a look at the <code>src/pages/</code> directory to add or change tabs,
                          update any existing page or create new pages.
                          </p>
                          <p>
                          Check bluetooth status:<br>
                          <strong><ion-input round id="ble_state" type="text" [(ngModel)]="ble_state"></ion-input></strong>
                          </p>
                          </ion-content>


                          home.ts



                          import { Component } from '@angular/core';
                          import { NavController } from 'ionic-angular';
                          import { DevicesService } from '../../providers/devicefactory/devicefactory';

                          @Component({
                          selector: 'page-home',
                          templateUrl: 'home.html'
                          })
                          export class HomePage {
                          public ble_state : string;

                          constructor(public navCtrl: NavController, public deviceProvider : DevicesService) {
                          //this.ble_state = ( this.deviceService.ble_status ? "Bluetooth is enabled" : "BLuetooth is disabled" );

                          //this.ble_state = deviceProvider.check_string;
                          this.ble_state = deviceProvider.getStatusString();
                          }

                          }


                          Before I put also directly in [(ngModel)] but it goes for blank page..... I think it's related something about passing variables maybe because if I comment that:



                          this.ble_state = deviceProvider.getStatusString();


                          the app appears working...
                          Maybe it's related about ionic and cordova installation platforms or dependencies even if it didn't reported any errors during compilation?



                          Thanks






                          share|improve this answer












                          Hello Rameez and saperlipopette,



                          I tried as both of you obtaining this:



                          devicefactory.ts



                          import { Injectable } from "@angular/core";
                          //import { BluetoothLE } from '@ionic-native/bluetooth-le';

                          @Injectable()
                          export class DevicesService {
                          public ble_status : boolean;
                          public check_string : any;

                          // public BLE : BluetoothLE
                          constructor(){
                          this.ble_status = false;
                          //this.BLE.initialize();
                          //this.BLE.isEnabled().then(result => { this.ble_status = result.isEnabled; });
                          this.check_string = "Provider enabled";
                          }

                          getStatus() { return this.ble_status; }
                          getStatusString() { return this.check_string; }

                          enableBLE() {
                          //if (this.ble_status) this.BLE.enable(); else this.BLE.disable();
                          if (this.ble_status) this.check_string = "Provider enabled"; else this.check_string = "Provider disabled";
                          }
                          }


                          app.module.ts



                          import { NgModule, ErrorHandler } from '@angular/core';
                          import { BrowserModule } from '@angular/platform-browser';
                          import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
                          import { HoergerateApp } from './app.component';

                          import { AboutPage } from '../pages/about/about';
                          import { ContactPage } from '../pages/contact/contact';
                          import { HomePage } from '../pages/home/home';
                          import { TabsPage } from '../pages/tabs/tabs';

                          import { StatusBar } from '@ionic-native/status-bar';
                          import { SplashScreen } from '@ionic-native/splash-screen';
                          import { SettingsPage } from '../pages/settings/settings';
                          import { DevicesService } from '../providers/devicefactory/devicefactory';


                          @NgModule({
                          declarations: [
                          HoergerateApp,
                          AboutPage,
                          SettingsPage,
                          ContactPage,
                          HomePage,
                          TabsPage
                          ],
                          imports: [
                          BrowserModule,
                          IonicModule.forRoot(HoergerateApp)
                          ],
                          bootstrap: [IonicApp],
                          entryComponents: [
                          HoergerateApp,
                          AboutPage,
                          SettingsPage,
                          ContactPage,
                          HomePage,
                          TabsPage
                          ],
                          providers: [
                          StatusBar,
                          SplashScreen,
                          DevicesService,
                          {provide: ErrorHandler, useClass: IonicErrorHandler}
                          ]
                          })
                          export class AppModule {

                          }


                          home.html



                          <ion-header>
                          <ion-navbar>
                          <ion-title>Home</ion-title>
                          </ion-navbar>
                          </ion-header>

                          <ion-content padding>
                          <h2>Welcome to Ionic!</h2>
                          <p>
                          This starter project comes with simple tabs-based layout for apps
                          that are going to primarily use a Tabbed UI.
                          </p>
                          <p>
                          Take a look at the <code>src/pages/</code> directory to add or change tabs,
                          update any existing page or create new pages.
                          </p>
                          <p>
                          Check bluetooth status:<br>
                          <strong><ion-input round id="ble_state" type="text" [(ngModel)]="ble_state"></ion-input></strong>
                          </p>
                          </ion-content>


                          home.ts



                          import { Component } from '@angular/core';
                          import { NavController } from 'ionic-angular';
                          import { DevicesService } from '../../providers/devicefactory/devicefactory';

                          @Component({
                          selector: 'page-home',
                          templateUrl: 'home.html'
                          })
                          export class HomePage {
                          public ble_state : string;

                          constructor(public navCtrl: NavController, public deviceProvider : DevicesService) {
                          //this.ble_state = ( this.deviceService.ble_status ? "Bluetooth is enabled" : "BLuetooth is disabled" );

                          //this.ble_state = deviceProvider.check_string;
                          this.ble_state = deviceProvider.getStatusString();
                          }

                          }


                          Before I put also directly in [(ngModel)] but it goes for blank page..... I think it's related something about passing variables maybe because if I comment that:



                          this.ble_state = deviceProvider.getStatusString();


                          the app appears working...
                          Maybe it's related about ionic and cordova installation platforms or dependencies even if it didn't reported any errors during compilation?



                          Thanks







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 20 at 17:51









                          Luigino

                          165213




                          165213






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387159%2fionic-3-pass-providers-variables-to-ion-input%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Wiesbaden

                              Marschland

                              Dieringhausen