Notice: The Monaca & Onsen UI Community Forum is shutting down.
For Onsen UI bug reports, feature requests and questions, please use the Onsen UI GitHub issues page. For help with Monaca, please contact Monaca Support Team.
Thank you to all our community for your contributions to the forum. We look forward to hearing from you in the new communication channels.
Osen ons.ready(...) and Ionic $ionicPlatform.ready(...)
-
I am looking at how to port bit of codes from an Ionic project to try out Onsen.
angular.module('starter', ['ionic']) .controller('AppController', function($scope, $ionicPlatform){ $ionicPlatform.ready(function() { $scope.function1 = function(){ // do something useful // ... blah blah ... alert("Hello World!"); } $scope.function1(); // Call function on ready. }); });
Now, for Onsen to do the same, is this the right way?
ons.bootstrap() .controller('AppController', function($scope) { }); ons.ready(function($scope) { $scope.function1 = function(){ // do something useful // ... blah blah ... alert("Hello World!"); } $scope.function1(); // Call function on ready. });
I notice that
ons.ready(...)
is not nested within a controller unlike Ionic’s$ionicPlatform.ready(...)
. So can functions inons.ready(...)
access the controller$scope
? Much apologies in advance, just an AngularJS newbie here.
-
@wetfeet no, you need to be inside the controller where you inject the
$scope
to be able to use it. The code you’re looking for in Onsen UI is pretty much the same:ons.bootstrap() .controller('AppController', function($scope){ ons.ready(function() { $scope.function1 = function(){ // do something useful // ... blah blah ... alert("Hello World!"); } $scope.function1(); // Call function on ready. }); });