如何在不使用 ionic-native 的情况下使用插件? [英] How to use a plugin without using ionic-native?

查看:18
本文介绍了如何在不使用 ionic-native 的情况下使用插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加cordova插件:cordova-plguin-ms-adal.因为ionic-native不支持这个插件.我不知道如何实现自己,所以我打开了一个问题,希望他们能很快合并这个插件.

与此同时,我等不及了.那么有没有什么方法可以在不使用ionic-native的情况下使用这个插件?

我在 home.ts 中尝试了以下代码,但无法访问.

<前>windows.plugins.Microsoft.ADAL.AuthenticationContext(s);

或直接

<前>Microsoft.ADAL.AuthenticationContext(s);

注意:- Microsoft 和 ADAL 是插件的命名空间- AuthenticationContext 是函数

解决方案

您可以在 ionic2 中使用cordova插件,尽管ionic-native不支持该插件.将所需的插件添加到您的项目中.

打开文件Plugins.xml"并检查clobbers 标签下的target 值.在您的情况下,它是 Microsoft.ADAL.AuthenticationContext 其中 Microsoft 是基类.

打开要使用插件的 ts 文件.使用 declare var Microsoft: any; 在 import 下,因为它是基类.然后将该方法调用为 Microsoft.ADAL.AuthenticationContext.your_method()

I want add the cordova plugin: cordova-plguin-ms-adal. Because this plugin is not supported in the ionic-native. I don't know how to implement myself, so I open an issue and hope they will merge this plugin very soon.

In the meantime, I can't wait. So is there any way to use this plugin without using ionic-native?

I tried the following code in my home.ts, but failed to reach.

windows.plugins.Microsoft.ADAL.AuthenticationContext(s);

or directly

Microsoft.ADAL.AuthenticationContext(s);

Note: - Microsoft and ADAL are the namespaces of the plugin - AuthenticationContext is the function

解决方案

You can use cordova plugin in ionic2 though the plugin is not supported by ionic-native. Add the required plugin to your project.

Open the file "Plugins.xml" and check for the target value under clobbers tag. In your case, it is Microsoft.ADAL.AuthenticationContext where Microsoft is the base class.

Open the ts file where you want to use the plugin.Use declare var Microsoft: any;under import as it is a base class. Then call the method as Microsoft.ADAL.AuthenticationContext.your_method()

这篇关于如何在不使用 ionic-native 的情况下使用插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆