2017-03-14 61 views
0

我想爲使用科爾多瓦的android構建一個AngularJS待辦事項列表應用程序。如果我在瀏覽器中打開頁面,頁面加載正常,但我無法獲取任何腳本在模擬器中運行,除了我放入全局範圍的alert()。這裏是我的index.html頁面代碼....科爾多瓦JavaScript無法在模擬器上工作

<html> 
    <head> 

     <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"/> 
     <meta name="format-detection" content="telephone=no"> 
     <meta name="msapplication-tap-highlight" content="no"> 
     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> 
     <link rel="manifest" href="/manifest.json"> 
     <link rel="stylesheet" type="text/css" href="css/index.css"> 

     <title>To-do list</title> 
    </head> 
    <body> 
     <div class="app" ng-controller="ToDoListController"> 
      <h1>Things to do.</h1> 
      <ul> 
       <li ng-repeat="item in list" ng-bind="item"></li> 
      </ul> 


     </div> 
     <script type="text/javascript" src="../node_modules/jquery/dist/jquery.min.js"></script> 
     <script type="text/javascript" src="../node_modules/angular/angular.min.js"></script> 
     <script type="text/javascript" src="../platforms/android/platform_www/cordova.js"></script> 
     <script type="text/javascript" src="js/index.js"></script> 
    </body> 
</html> 

而對於index.js頁:

$(document).ready(function(){ 
    document.addEventListener('deviceready', function(){ 

    }); 
    angular.module('ToDo',[]) 
     .controller('ToDoListController',['$scope',function($scope){ 
      $scope.list = ["FOO","BAR"]; 
     }]); 
    angular.bootstrap(document,['ToDo']); 
    $('ul').append('<li>Item appended</li>'); 
}); 

正如我說,如果我在全球把警報()部分如果index.js,它會觸發,但沒有別的會。無論是在$(document).ready()還是在它之外,angular bootsrap和jquery append函數都不會執行。在瀏覽器中一切正常。任何幫助表示讚賞。

+0

你需要的一切你要採購是本地到你的'www'目錄。 'node_modules'中的文件不會被複制,並且在您的應用程序中將丟失。因此,你的問題的一部分。 另一個問題是,你應該永遠只能源''使用SRC =「cordova.js」'cordova.js';在構建應用程序時將提供相應的文件。 –

+0

這樣做。非常感謝你! – lpuccio

回答

0

通過凱里Shotts,在上面評論:

你需要的一切你要採購是本地到你的www目錄。您的node_modules中的文件不會被複制,並且在您的應用中將會丟失。因此,你的問題的一部分。另一個問題是你應該只使用src =「cordova.js」來源代碼cordova.js;在構建應用程序時將提供相應的文件。

這個工作。謝謝!

相關問題