Ionic Series--using Ng-cordova plug-in

Source: Internet
Author: User


1, Cordova introduction


Cordova provides a set of device-related APIs that enable mobile apps to access native device features, such as cameras, microphones, and so on, with JavaScript.



Cordova supports the following 7 mobile operating systems: IOS, Android,ubuntu phone OS, Blackberry, Windows phone, Palm WebOS, Bada and Symbian.



Cordova is an open source project for Apache, the core code drawn from PhoneGap, and the only difference between the current (PhoneGap and Apache Cordova) is the name of the downloaded package, which lasts for a while.


2, Ng-cordova introduction


Ngcordova is a series of open-source ANGULARJS services and extensions encapsulated on the Cordova API, enabling developers to easily invoke device capabilities in HYBRIDAPP development, where the device capabilities API can be accessed in Angularjs code.



In the Cordova plug-in sucess and Error JS callback method, is unable to use Angularjs $scope object and injected method, can only access global methods and variables, which will cause a lot of trouble, must use the traditional JS method to write a lot of ugly code. Using Ngcordova should solve this problem.


3 . The relationship between Phonegap and Cordova


Adobe will continue to provide phonegap in a combination of Cordova plus phonegap build and Adobe Shadow. As early as October 2011, Adobe acquired Nitobi Software and its PhoneGap products, and then announced that the mobile development framework would continue to open source and submit it to Apache incubator in order to fully accept ASF's governance. We want to know why Adobe acquires Nitobi and open source PhoneGap, especially why PhoneGap will continue if another project should do its job?



Adobe has recently had a series of communication issues, including dealing with transitions from flash, Flex, air, and PhoneGap. A few months later, Adobe finally figured out their plans for Flash and Flex, and now post a clarification about some of the mysteries surrounding PhoneGap.



PhoneGap's project director, Brian Leroux, pointed out that the decision to open source PhoneGap was made before Adobe bought Nitobi, and because Adobe now owns the PhoneGap logo, they have to change their name. The first selected name is callback, no originality, so change again, the product is now called Apache Cordova.



Although many people think that the name PhoneGap will not be used again, because the code is under a different name, but the reality is that Adobe would like to continue to provide Cordova under the PhoneGap brand. In the near future, Adobe will pack Cordova, PHONEGAP build (an online application building service) and Adobe Shadow (a check and preview tool) and will likely add more mobile development tools to the PHONEGAP package in the future.



It is unclear whether Adobe will consolidate the PhoneGap brand, though developers are familiar with it, or if it is replaced by another name. It is also unclear whether they will build private code on top of the Cordova code, but Leroux's post leaves a clue: "The only difference between the current (PhoneGap and Apache Cordova) is the name of the downloaded package, which lasts for a while (aggravating tone). "


4, Ng-cordova installation and use4.1. Download Ng-cordova
Bower Install Ngcordova
4.2. Introduction of Ng-cordova.js file


Putng-cordova.jsor ng-cordova.min.js Introduced into index.html and placed cordova.jsbefore, AngularJS Ionic file (because Ngcordova D relies on AngularJS).


<script src= "Lib/ngcordova/dist/ng-cordova.js" ></script> <script src= "Cordova.js" ></script >
4.4, the introduction of Ng-cordova dependence


Introduction of Ng-cordova dependencies in the app.js of the main program


Angular.module (' myApp ', [' Ngcordova '])
4.5. Add plugins to your Cordova CLI environment
Cordova Plugin Add ...
4.6. Use


To use after checking that the device is ready to complete


document.addEventListener("deviceready", function () {   
    $cordovaPlugin.someFunction().then(success, error); 
}, false);

 // OR with IONIC 
 
$ionicPlatform.ready(function() {  
      $cordovaPlugin.someFunction().then(success, error); 
});


But I've tested it, because it's already run, and your various features are definitely behind it, so you can use it later. However, if some of the functions are to start the application will have, or to write in the face.


angular.module(‘starter‘, [‘ionic‘, ‘route‘,‘config‘,‘global‘,‘commonJs‘,‘ngCordova‘])

.run([‘$ionicPlatform‘,‘$rootScope‘, ‘$location‘, ‘$timeout‘, ‘$ionicHistory‘,‘CommonJs‘,‘$cordovaToast‘,function($ionicPlatform,$rootScope, $location, $timeout, $ionicHistory,CommonJs,$cordovaToast) {
  $ionicPlatform.ready(function() {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleLightContent();
    }
  });
  
}]);
4.7. Official website


Ng-cordova Plug-in collection: http://ngcordova.com/docs/plugins/













Ionic Series--using Ng-cordova plug-in


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.