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?