title: "TypeError: Cannot read property 'nav' of undefined" in Ionic
body: <p>I raised a similar question two days back, but this time I am getting the same error when I run the code in an actual device or simulator. On a regular browser it works fine.</p>
  
  <p>Here is my app.component.ts code: </p>
  
  <pre><code>import { Component, ViewChild } from '@angular/core';
  import { Platform } from 'ionic-angular';
  import { StatusBar } from '@ionic-native/status-bar';
  import { SplashScreen } from '@ionic-native/splash-screen';
  import { HomePage } from '../pages/home/home';
  import { LoginPage } from '../pages/login/login';
  import {NativeStorage} from '@ionic-native/native-storage';
  import { NavController } from 'ionic-angular';
  
  @Component({
    templateUrl: 'app.html'
  })
  
  export class MyApp {
    rootPage:any = LoginPage;
    @ViewChild('navApp') nav : NavController;
    constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private nativeStorage: NativeStorage,) {
      platform.ready().then(() =&gt; {
           this.nativeStorage.getItem('userExists').then((data)=&gt;{
           this.nav.push(HomePage);
          console.log(data.userExists);
         },(error)=&gt;{
          console.log("No Data in Local Storage");
              this.nav.push(LoginPage);
        })
  
        statusBar.styleDefault();
        splashScreen.hide();
      });
    }
  
  }
  </code></pre>
  
  <p>This is my app.html </p>
  
  <pre><code>&lt;ion-nav #navApp [root]="rootPage"&gt;&lt;/ion-nav&gt;
  </code></pre>
  
  <p>This is my version info</p>
  
  <pre><code>global packages:
  
      @ionic/cli-utils : 1.2.0
      Cordova CLI      : 7.0.1
      Ionic CLI        : 3.2.0
  
  local packages:
  
      @ionic/app-scripts              : 1.3.7
      @ionic/cli-plugin-cordova       : 1.2.1
      @ionic/cli-plugin-ionic-angular : 1.2.0
      Cordova Platforms               : android 6.2.3
      Ionic Framework                 : ionic-angular 3.2.1
  
  System:
  
      Node       : v6.10.2
      OS         : Windows 10
      Xcode      : not installed
      ios-deploy : not installed
      ios-sim    : not installed
  </code></pre>
  
  <p>Package.json:</p>
  
  <pre><code>{
      "name": "myapp",
      "version": "0.0.1",
      "author": "Ionic Framework",
      "homepage": "http://ionicframework.com/",
      "private": true,
      "scripts": {
          "clean": "ionic-app-scripts clean",
          "build": "ionic-app-scripts build",
          "lint": "ionic-app-scripts lint",
          "ionic:build": "ionic-app-scripts build",
          "ionic:serve": "ionic-app-scripts serve"
      },
      "dependencies": {
          "@angular/common": "4.1.0",
          "@angular/compiler": "4.1.0",
          "@angular/compiler-cli": "4.1.0",
          "@angular/core": "4.1.0",
          "@angular/forms": "4.1.0",
          "@angular/http": "4.1.0",
          "@angular/platform-browser": "4.1.0",
          "@angular/platform-browser-dynamic": "4.1.0",
          "@ionic-native/core": "3.7.0",
          "@ionic-native/facebook": "^3.10.2",
          "@ionic-native/native-storage": "^3.10.3",
          "@ionic-native/splash-screen": "3.7.0",
          "@ionic-native/status-bar": "3.7.0",
          "@ionic/storage": "2.0.1",
          "cordova-android": "^6.2.3",
          "cordova-plugin-console": "^1.0.5",
          "cordova-plugin-device": "^1.1.4",
          "cordova-plugin-facebook4": "^1.9.0",
          "cordova-plugin-nativestorage": "^2.2.2",
          "cordova-plugin-splashscreen": "^4.0.3",
          "cordova-plugin-statusbar": "^2.2.2",
          "cordova-plugin-whitelist": "^1.3.1",
          "ionic-angular": "3.2.1",
          "ionic-native": "^2.5.1",
          "ionic-plugin-keyboard": "^2.2.1",
          "ionicons": "3.0.0",
          "rxjs": "5.1.1",
          "sw-toolbox": "3.6.0",
          "zone.js": "0.8.10"
      },
      "devDependencies": {
          "@ionic/app-scripts": "1.3.7",
          "@ionic/cli-plugin-cordova": "^1.2.1",
          "@ionic/cli-plugin-ionic-angular": "^1.2.0",
          "typescript": "2.2.1"
      },
      "description": "An Ionic project",
      "cordova": {
          "plugins": {
              "cordova-plugin-console": {},
              "cordova-plugin-device": {},
              "cordova-plugin-splashscreen": {},
              "cordova-plugin-statusbar": {},
              "cordova-plugin-whitelist": {},
              "ionic-plugin-keyboard": {},
              "cordova-plugin-facebook4": {
                  "APP_ID": "305938313175123",
                  "APP_NAME": "myapp"
              },
              "cordova-plugin-nativestorage": {}
          },
          "platforms": [
              "android"
          ]
      }
  }
  </code></pre>