在角度4打字稿文件中使用cordova插件,无需离子

问题描述 投票:0回答:1

我想用angular4创建一个移动应用程序。我已经使用角度CLI创建了一个角度项目,现在我想在我的角度项目中使用/实现cordova插件。如何在不使用IONIC框架的情况下这样做?

例如:我想使用cordova网络信息插件来获取我的应用程序中当前网络的状态。

android angular cordova-plugins
1个回答
0
投票

你应该安装和集成你的角度项目与cordova(它没有IONIC可行)。

我建议阅读这些文章。

1)https://www.becompany.ch/en/blog/2016/10/19/creating-apache-cordova-app-with-angular2

2)https://www.becompany.ch/en/blog/2017/05/31/update-angular-cli-and-apache-cordova

并使用此repo作为示例(cordova-integration分支):

https://github.com/becompany/angular2-rss-reader-tutorial/tree/cordova-integration

这有点旧,但即使使用Angular 5+,我也会使用这种方法进行Angular + Cordova项目。

在那里,您可以将任何现有插件添加到Cordova应用程序。

更新:要在TS文件中使用某些插件,您应该在文件中声明该变量,如下例所示:

declare const PushNotifications;

并检查它是否存在并使用:

if (window['PushNotification']) {
  PushNotification.init(...);
}

像这样的Smth。

© www.soinside.com 2019 - 2024. All rights reserved.