Search code examples
javascriptonsen-ui

Onsen + pushPage + options.onTransitionEnd


I try to use the options.onTransitionEnd available on pushPage() because I would like to call a $scope.init() function inside the controller of the pushed page.

I saw that I can just pass ONLY an anonymous function to the onTransitionEnd option.

For example:

app.navi.pushPage('page.html', {onTransitionEnd: function(){ alert('ok') }  } );

There is instead a way to call a $scope function inside the controller of the pushed page?

Tks a lot. David


Solution

  • You can pass a function in this way as long as the button is in NavigatorController scope:

    <ons-button ng-click="myNav.pushPage('page1.html', {onTransitionEnd: myFunction})">Push</ons-button>

    ons.bootstrap()
    .controller('NavigatorController', function($scope) {
      $scope.myFunction = function () {
        console.log('onTransitionEnd');
      };
    });
    

    Check it here: http://codepen.io/frankdiox/pen/Gpzvqw

    In any case, if what you want is to initialize the pushed page perhaps it's easier to use page events (only pageinit is available for Onsen UI 1.x): http://onsen.io/guide/overview.html#Pagelifecycle

    Of course, the pushed page's controller will run as well.