How to manage page routes in the controller?

OnsenUI is excellent. Quick and easy. However, there is not much documentation in the controller for managing Onsen logic.

Like, for example, I want to make $ location.path ('/ newpath') inside the controller. How is this done in Onsen? I tried "ons.navigator.pushPage (" partials / latestjob.html "); in my controller function, but it doesn’t work. Are we restricted ng-click in Onsen to go to another page?

Thank.

+4
source share
1 answer

In Onens UI 1.04, you can access the navigator from inside the controller as follows.

$rootScope.ons.navigator.pushPage('new_page.html');

Another way -

$rootScope.ons.$get('#navigator').pushPage(pagename);

where #navigator- is idthe navigator, which you put the st

<ons-navigator id="navigator" page="page1.html"></ons-navigator> 

, .

- . ,

var element = document.querySelector( ".navigator-container");
var scope = angular.element( element ).scope();
scope.pushPage(pagename);

.navigator-container - onsen ui navigator. onsen ui 1.0.

: $rootScope

myapp.controller('myCtrl', function($scope, $rootScope) {
  $scope.pushPage = function(pagename) {
    $rootScope.ons.navigator.pushPage(pagename);
  }
});
+2

Source: https://habr.com/ru/post/1543066/


All Articles