How to use a plugin without using ionic-native?

2019-02-20 14:42发布

问题:

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

回答1:

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()