I generated the skeleton of the app with phonegap-angular-seed and he created a factory with the phonegap event deviceready according to this link. How should I call this event properly on my Angularjs controller?
1 Answer
So this is just a simple service that returns a callback function for your use once the event has fired.
First you need to add the dependency for the service in your module definition.
var app = angular.module('myApp', ['App.services']);
Then you can inject the cordovaReady into your controller.
app.controller('myController', ['$scope', 'cordovaReady', function($scope, cordovaReady) {
cordovaReady(function () {
// Device ready event has fired when this function fires
});
}]);
2 Comments
Daniel Faria
cordovaready is the factory name but how can i call deviceready event on controller??
Michael Tempest
cordovaReady takes a function as a parameter, this function is called when the device ready event is fired. Look above