gpt4 book ai didi

typescript - ionic 2 : Use cordova plugin with Typescript that has its own namespace

转载 作者:搜寻专家 更新时间:2023-10-30 21:10:39 24 4
gpt4 key购买 nike

我想使用 LibraryHelper plugin在我的 Ionic 2 应用程序中,但它的文档静态定义了它的用法,例如:

LibraryHelper.saveVideoToLibrary(....)

不通过:

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

当我在 Typescript .ts 文件中写入第一行时,出现错误:

找不到名称“LibraryHelper”

问)我如何将 LibraryHelper 插件导入到我的 Ionic 2 应用程序中,并且能够在没有它的情况下引用它 - 如上所述未定义?

最佳答案

确保使用--save 选项安装插件

ionic plugin add cordova-library-helper --save 

您需要在导入后在类中声明全局对象 LibraryHelper

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

当你在你的组件中使用时,确保包裹在

this.platform.ready().then(()=>{
LibraryHelper.saveVideoToLibrary(....)
})

关于typescript - ionic 2 : Use cordova plugin with Typescript that has its own namespace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42530549/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com