Search code examples
javascriptangularjscordovaonsen-ui

Get navigator variable in angular.run


I'm using onsen ui with angular and I would like to set my first navigator page in angular run:

if (....) navigator.pushPage('page1.html) or navigator.pushPage('page2.html)

But even with ons.ready, I can't find my navigator variable.

My html:

<ons-navigator var="appNavigator"></ons-navigator>

<script>
  document.addEventListener("deviceready", function () {

    // start Angular and onsen once device is ready (to avoid cordova plugin issues)
    angular.bootstrap(document, ["wesapp", "onsen", 'templates']);

  }, false);
</script>

My angular.run :

 var firstPageUrl;

  if ($rootScope.settings.monNom && $rootScope.settings.monPrenom && $rootScope.settings.monEmail) {
    firstPageUrl = 'app/views/home.page.html';
  } else {
    firstPageUrl = 'app/views/home-info.html';
  }

  ons.ready(function() {
    appNavigator.pushPage(firstPageUrl, {animation: none});
  });

And when I launch my app I get this error:

none is not defined

Solution

  • Set the animation key value to a 'none' string.

    appNavigator.pushPage(firstPageUrl, {animation: 'none'});