简体   繁体   English

Cordova和Angular:插件不起作用

[英]cordova and angular: plugins not working

i'm new about Angular and Cordova. 我是Angular和Cordova的新手。 I'm using Cordova 6.2 and angular 1.5.6. 我正在使用Cordova 6.2和angular 1.5.6。 I can get plugins working if i create a new cordova project but i cannot in my angular app. 如果创建一个新的cordova项目,我可以使插件正常工作,但是我无法在我的角度应用程序中使用。 My issue born when i had to set the StatusBarOverlaysWebView = false in IOS system and couldn't make it work (both in iphone 5s, iphone 6 and in emulator too). 我的问题出在我必须在IOS系统中设置StatusBarOverlaysWebView = false并且无法使其工作时出现(在iPhone 5s,iPhone 6和仿真器中也是如此)。 I tried to use other plugins but none didn't work. 我尝试使用其他插件,但没有一个没有用。 I googled and found that the problem can be calling the plugin after angular is loaded and that i needed to bootstrap angular manually to get the plugins working (calling them after application/device is ready). 我在Google上搜索,发现问题可能是在angular加载后调用了插件,并且我需要手动引导angular才能使插件正常工作(在应用程序/设备准备就绪后调用它们)。 I followed instructions and made a lot of trying but i cannot get this work. 我按照指示进行了很多尝试,但是我无法完成这项工作。 I cannot even fire a console log on the device ready event copying code from the cordova device ready base example from a new cordova project. 我什至不能从新的cordova项目中的cordova设备就绪基础示例中的设备就绪事件复制代码上触发控制台日志。

Cannot getting even StatusBar, splashscreen working on IOS. 甚至无法获得StatusBar,启动屏幕也无法在IOS上运行。

Maybe i'm just missing a missy thing. 也许我只是想念一件可疑的事情。

Here's my code, thank you! 这是我的代码,谢谢!

myApp.js myApp.js

window.addEventListener('deviceready', function onDeviceReady() {
    //Never fired!!!!!!
    console.log("readydevice");
    StatusBar.overlaysWebView(false);
    angular.bootstrap(document, ['myApp']);
    StatusBar.overlaysWebView(false);

}, false);

window.addEventListener('DOMContentLoaded', function onDeviceReady() {
    //Fired but console returns: StatusBar is not defined 
    console.log("readyDom");
    StatusBar.overlaysWebView(false);
    angular.bootstrap(document.body, ['myApp']);
    StatusBar.overlaysWebView(false);

}, false);



angular.module('myApp', [
    'ngRoute',
    'mobile-angular-ui',
    'ngSanitize'
]);

index.html index.html

<!doctype html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0"/>
    <title>My app</title>
    <link rel="stylesheet" href="dist/css/mobile-angular-ui-base.min.css"/>
    <link rel="stylesheet" href="dist/css/general.css"/>
    <link rel="stylesheet" href="dist/css/custom.css"/>
    <script src="dist/js/winstore-jscompat.js"></script>
    <script src="dist/js/angular.min.js"></script>
    <script src="dist/js/angular-route.min.js"></script>
    <script src="dist/js/angular-sanitize.min.js"></script>
    <script src="dist/js/mobile-angular-ui.min.js"></script>
    <script src="dist/js/mobile-angular-ui.gestures.min.js"></script>
    <script src="javascript/config.js"></script>

</head>
<body ng-csp="">

<div class="app">
    <top-bar></top-bar>

    <div class="app-body">
        <div ng-view class="app-content scrollable-content"></div>
    </div>

    <menu-bottom></menu-bottom>

</div>

<script src="javascript/myApp.js"></script>
<script src="javascript/controllers/route.js"></script>
<script src="javascript/controllers/controller.js"></script>
<script src="javascript/directives/directive.js"></script>
</body>
</html>

config.xml config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.com" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>My App</name>
    <description>
        My App
    </description>
    <author email="develop@example.com" href="http://www.example.com">
        My Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <access launch-external="yes" origin="tel:*" />
    <access launch-external="yes" origin="mailto:*" />
    <engine name="ios" spec="~4.1.1" />
    <engine name="android" spec="~5.1.1" />
    <engine name="windows" spec="~4.3.2" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <preference name="AutoHideSplashScreen" value="true" />
    <preference name="splashscreen" value="splash" />
    <preference name="SplashScreenDelay" value="1000" />
    <preference name="Fullscreen" value="false" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="Orientation" value="portrait" />
    <preference name="StatusBarOverlaysWebView" value="false" />
    <preference name="StatusBarBackgroundColor" value="#000000" />
    <preference name="StatusBarStyle" value="default" />
    <platform name="android">
        <allow-intent href="market:*" />
        <!--<splash density="land-hdpi" src="res/images/splash.png" />-->
        <!--<splash density="port-hdpi" src="res/images/splash.png" />-->
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
        <preference name="SuppressesIncrementalRendering" value="true" />
        <!--<splash src="res/images/ios/Default~iphone.png" width="320" height="480"/>-->
        <!--<splash src="res/images/ios/Default@2x~iphone.png" width="640" height="960"/>-->
    </platform>
    <icon src="res/images/icon.png" />

</widget>

I just needed to add: 我只需要添加:

<script type="text/javascript" src="cordova.js"></script>

in index.html. 在index.html中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM