GithubHelp home page GithubHelp logo

ramonornela / ionic-native Goto Github PK

View Code? Open in Web Editor NEW

This project forked from danielsogl/awesome-cordova-plugins

1.0 1.0 0.0 4.14 MB

Native features for mobile apps built with Cordova/PhoneGap and open web technologies. Complete with TypeScript support. The successor to ngCordova. Pairs exquisitely with a nice bottle of Ionic Framework.

Home Page: http://ionicframework.com/docs/v2/native/

License: Other

JavaScript 10.57% Shell 1.44% HTML 0.50% TypeScript 87.48%

ionic-native's Introduction

Circle CI Commitizen friendly npm

NPM NPM

Ionic Native

Ionic Native is a curated set of wrappers for Cordova plugins that make adding any native functionality you need to your Ionic, Cordova, or Web View mobile app easy.

Documentation

For the full Ionic Native documentation, please visit http://ionicframework.com/docs/v2/native/.

Promises and Observables

Ionic Native wraps plugin callbacks in a Promise or Observable, providing a common interface for all plugins and ensuring that native events trigger change detection in Angular 2.

import { Geolocation } from 'ionic-native';

Geolocation.getCurrentPosition().then(pos => {
  console.log('lat: ' + pos.coords.latitude + ', lon: ' + pos.coords.longitude);
});

let watch = Geolocation.watchPosition().subscribe(pos => {
  console.log('lat: ' + pos.coords.latitude + ', lon: ' + pos.coords.longitude);
});

// to stop watching
watch.unsubscribe();

Angular 1

Ionic Native works as a stand-in for ngCordova. In many cases, the usage is identical, but we import ionic.native instead of ngCordova as our module.

As a rule of thumb: take the ES6 class name of the plugin and add $cordova to get the service name. For example, Geolocation would be $cordovaGeolocation, and Camera will be $cordovaCamera:

angular.module('myApp', ['ionic', 'ionic.native'])

.controller('MyCtrl', function($scope, $cordovaCamera) {
  $scope.takePicture = function() {
    $cordovaCamera.getPicture(opts).then(function(p) {
    }, function(err) {
    });
  };
});

For services that return observables, the Angular 1 digest cycle must be done manually (currently):

angular.module('myApp', ['ionic', 'ionic.native'])

.controller('MyCtrl', function($scope, $cordovaGeolocation) {
  $scope.takePicture = function() {
    $cordovaGeolocation.watchPosition(opts).subscribe(function(p) {
      $scope.$apply(function() {
        $scope.position = p.coords;
      });
    }, function(err) {
    });
  };
});

Runtime Diagnostics

Spent way too long diagnosing an issue only to realize a plugin wasn't firing or installed? Ionic Native lets you know what the issue is and how you can resolve it.

img

Installation

Run following commmand to install ionic-native in your project.

npm install ionic-native --save

Plugin Missing?

Let us know or submit a PR! Take a look at the Developer Guide for more on how to contribute. ❤️

Credits

Ibrahim Hadeed - @ihadeed

Tim Lancina - @timlancina

Max Lynch - @maxlynch

Rob Wormald - @robwormald

ionic-native's People

Contributors

amuramoto avatar barryrowe avatar chogarcia avatar cmanou avatar dudeofawesome avatar fablouis avatar glecaros avatar guillenotfound avatar ihadeed avatar imhoffd avatar ionitron avatar keithdmoore avatar kessiler avatar marcinwadon avatar matiastucci avatar mattlewis92 avatar mhartington avatar mlynch avatar nickgal avatar panuganti avatar patrickbussmann avatar perrygovier avatar ramonornela avatar rapropos avatar ritzlgrmft avatar tlancina avatar tlaverdure avatar vfdev-5 avatar walkingriver avatar xueron avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.