angularjs - Using ngCordova plugins without calling them in app.js? -


my app looking good, ionic. core info there , i'm adding frills - email, sharing, media (one of functions metronome) , on.

i can't plugins work.

i've had success previous ionic app plugins called within

.run(function($ionicplatform) {    $ionicplatform.ready(function() {    } } 

and indeed statusbar plugin seems working fine , called within there.

i'm using side menu starter tabs built in btw.

my issue, suppose, i've 3 controller files. main_ctrls.js - main app menu_ctrls.js - menu pages feedback , email, analytics extras_ctrls.js - "extra" section metronome , on.

i've put 'ngcordova' dependency in each module , called plugin within controller ready function. here email controller.

angular.module('menu.controllers', ['ngcordova'])  .controller('feedctrl', function($ionicplatform, $scope, $cordovaemailcomposer) {    $ionicplatform.ready(function() {      $cordovaemailcomposer.isavailable().then(function() {       // available       alert('email available');     }, function () {       // not available       alert('email not available');     });      var email = {       to: 'max@mustermann.de',       cc: 'erika@mustermann.de',       bcc: ['john@doe.com', 'jane@doe.com'],       attachments: [         'file://img/logo.png',         'res://icon.png',         'base64:icon.png//ivborw0kggoaaaansuheug...',         'file://readme.pdf'       ],       subject: 'cordova icons',       body: 'how you? nice greetings leipzig',       ishtml: true     };      $cordovaemailcomposer.open(email).then(null, function () {       alert('email discarded.');     });   }) }); 

i'm testing on android (nexus 4 android 5.1) chrome inspect , error saying "cannot read property 'isavailable' of undefined". needless say, alerts don't pop up.

this happens plugins called within controllers in way.

what doing wrong?

it seems invoking plugins before cordova device ready fired. in angularjs application have done following. 1. removed ng-app html , did manual bootstrap through script 2. added cordova.js file dependency. ( last dependency. after ng-cordova js) 3. placed cordova.js in same folder of index.html. (no explanation why. other location, not getting added. may specific pertaining cordova.) 4. added following script index.html

<script type="text/javascript" language="text/javascript">  $(document).ready(function() {     document.addeventlistener("deviceready", ondeviceready, false); });   ondeviceready = function() {     alert("hello!");      angular.element(document).ready(function() {     angular.bootstrap(document, ["main"]); }); }; </script> 

here "main" main angularjs module. ensures app loaded after device ready event fired cordova , cordova related functions available. specific ionic donot have anycode. may portion ionic bootstraps app can put instead of angular.bootstrap.

my assumptions: have added plugins cordova project through command

cordova plugin add <plugin-location> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -