Ionic 2 with ng-cordova

hello everyone

i want to add ng-cordova plugins to ionic 2 app but i am not able to find any help on this any hep will be appreciated thank you

I wanter to add push notification plugin the docmentation specififed in ionic v2 tutorial is not working

fitst
npm install -g ionic@alpha and npm install -g cordova,
then
cordova plugin add https://… or ionic plugin add https://…

thank you very much for the reply but i want to intergrate ngcordova first i am not able to install ng-cordova

I actually just had a chat to Mike Hartington about this - ngCordova won’t be used in Ionic 2. You’ve probably noticed some plugin interfaces provided directly in Ionic 2 already (like Geolocation, Camera etc.) - Ionic will provide interfaces for all the core plugins, but for any others you will just need to create and import your own class (or use one created by the community, which I’m sure there will be plenty of as time goes on).

If that’s not something you feel comfortable doing, of course you can still just use the plugin directly without the promise / ngCordova style structure.

is it possible to use push notification with ionic 2 currently the example specified in their docs is not working

Hi @joshmorony,

could u please explain little bit more about using plugins listed in ngCordova, but not yet implemented directly in ionic2

I’m trying to implement SocialSharing with ionic2.

I’m basically confused with 2 approaches

  1. When I see the current ionic2 plugins here, they seems to be importing the component from ionic core.

E.g. import {Camera} from 'ionic/ionic';

but I’m not sure how to import the SocialSharing plugin as above.

  1. When I had a look on the SocialSharing plugin ngCordova implementation , it seems like its using

E.g . $window.plugins.socialsharing

I’m not sure how to get the $window variable with ionic2 and do I need to using any import statements to load the cordova plugin ?

appreciate if you could point me to the right direction.

and I’m defiantly keen to know if @hussainanver52 has found a solution ?

cheers,

Sam

For any plugins that haven’t been implemented in Ionic 2 yet, you can just use it as you would in any Cordova application (without the ngCordova / Ionic 2 style promises which make it a little nicer to implement).

In the case of the social sharing plugin, just install the plugin in your project and trigger it in your code like this:

window.plugins.socialsharing.share('Message only')

Just follow the documentation available for the plugin on GitHub, not the ngCordova docs.

1 Like

Hey @joshmorony, thanks for the answer. I’ll try that. And I’ll read more about cordova as then I’ll have a better understanding

thanks again

cheers

thanks a lot its working fine
can you help me for inifinite scroll with ionic 2

Infinite scroll hasn’t been added to Ionic 2 yet.

Hi all, any chance someone got the Camera plugin to work? As i have understood, these plugins are temporarily moved out from the ionic2, and are to be moved back sometime, right? I have had much joy from blogpost written by @joshmorony and others, and almost broke the internet in googling for a viable approach of getting the Camera plugin to work, to no avail. I’ve installed it in the project, but it doesn’t seem to be available as an import {Camera } from ‘ionic/ionic’?
Running latest cordova and ionic. Got the network and geolocation plugins running without problems.
takePhoto() { this.platform.ready().then(() => { Camera.getPicture({ }).then(data => { alert('Data', data); }, err => { alert('Unable to take picture') }) } }
Nothing happens, “Camera” is undefined
The alerts as debug is because i’m on a chromebook with crouton, and i have not been able to get the android emulator running, so i’m building .apk:s for debugging… A little tedious.

The Camera plugin hasn’t been ‘removed’ from Ionic 2, the interface for it has been (all plugins have). We will likely see something added in the future (they are working on something called Ionic native), but that doesn’t mean you can’t use Cordova plugins now.

Cordova plugins can be added to any project, it’s not specific to Ionic, and in general when you add a plugin it is just made available as a global object in your app. To use it you just need to follow the documentation here: https://github.com/apache/cordova-plugin-camera

In short, you can do this:

ionic plugin add cordova-plugin-camera

and then to take a photo:

let options = {
  quality: 100,
  destinationType: Camera.DestinationType.FILE_URI,
  sourceType: Camera.PictureSourceType.CAMERA,
  encodingType: Camera.EncodingType.JPEG,
  saveToPhotoAlbum: true
};

navigator.camera.getPicture(

  (imagePath) => {
    console.log(imagePath);
  },

  (error) => {
    console.log(error);
  }, options

);

I’m using the ES6 fat arrow functions here, but you can just use normal function callbacks if you want (which is what is used in the camera plugin docs)

2 Likes

Wow.
This just works. Thank you so much!
"you just made my day".toUpperCase()

Can you share your code? I got problem to make this plugin work. Please refer to my question here:

Thanks.

I tried the same but “navigator” is undefined as well.

Any idea why?

I did some tests. After you add any plugin, you have to run something like ionic build ios to make it work. Otherwise it always shows “is undefined” error.

1 Like

thanx. in my case

ionic build android

Did the job.

The documentation is misleading (“navigator. was not mentioned there”).
Fixing it will boost Ionic v2 adoption :iphone:

Hi !
i’m with a similar problem with iOS, Android works fine.
I’ve installed cordova-sqlite-storage and https://github.com/danwilson/google-analytics-plugin.git.

using like this:
this.storage = new Storage(SqlStorage);
platform.ready().then(() => {
window.analytics.startTrackerWithId(‘UA-62380044-1’);
console.log(“device.uuid”, device.uuid);
window.analytics.setUserId(device.uuid);
window.analytics.enableUncaughtExceptionReporting(true, function(s){console.log(s)}, function(e){console.error(e)});
});

looks like not installed:
undefined is not an object (evaluating ‘window.analytics.startTrackerWithId’)
Storage: SQLite plugin not installed, falling back to WebSQL. Make sure to install cordova-sqlite-storage in production!

Someone having a same issue?

In your case the error is in the analytics plugin, SqLite is installed but in browser doesn’t exist so it fall back to WebSql.
Which analytics is that? google analytics?

yep, google analytics.
now, i’ve removed the platform and add again (after multiple times) and the analytics worked.

i’m running in a tablet, inspecting with safari, why SQLite still not working?