Question

I'm building a songbook (with chords) with PhoneGap. Each song is stored in separate file, index is held in one of the files.

What I need is to be able to run some Javascript function every time a page is pushed. Meaning:

In index.html I have:

<li class="…" ng-click="ons.navigator.pushPage('page.html')">
<span class="topcoat-list__item__line-height">Some song</span>
</li> 

What should I put where to run Javascript function when page.html is pushed?

Était-ce utile?

La solution

AngularJS Controller resolve this. For example,

<div ng-controller="MyCtrl">
  <div ng-click="pushPage('page2.html')"><span>Some song</span></div>
</div>

and in app.js

app = angular.module('myApp', ['onsen.directives']);

app.controller('MyCtrl',function($scope,$rootScope) { 

    $scope.pushPage = function(pagename) {
        /* call some function */
        alert("OK");
        /* call some function end */

        $rootScope.ons.navigator.pushPage(pagename);
    }    
} );
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top