3

I want to use the LibraryHelper plugin in my Ionic 2 app, but the docs for it defines its usage statically, e.g.:

LibraryHelper.saveVideoToLibrary(....)

NOT through:

window.plugins.LibraryHelper.saveVideoToLibrary(....

When I write the first line in my Typescript .ts file, I get the error:

Cannot find name 'LibraryHelper'

Q) How do I import the LibraryHelper plugin into my Ionic 2 app and be able to reference it without it - being undefined as above?

1 Answer 1

2

Make sure to install the plugin with the --save option

ionic plugin add cordova-library-helper --save 

You need to declare the global object LibraryHelper in your class after your imports.

//imports
declare var LibraryHelper:any;
@Component({..})
//..

When you are using in your component, just make sure to wrap within

this.platform.ready().then(()=>{
  LibraryHelper.saveVideoToLibrary(....)
})
Sign up to request clarification or add additional context in comments.

5 Comments

I've done exactly that and the LibraryHelper object is just empty when I try to use it: {}
you are testing on a device?
gajotres.net/ionic-2-how-to-use-cordova-plugins I listed the steps you do for any general cordova plugin..Maybe it has to do with the plugin itself
Ok, well you fixed the typescript error, so you win! Thanks for your help.
ok..if it helps you can check out ionicframework.com/docs/v2/native and see if any of it fits your use case its easier to integrate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.