【问题标题】:PhoneGap not running Angular JS codePhoneGap 没有运行 Angular JS 代码
【发布时间】:2017-11-15 00:39:22
【问题描述】:

我刚开始使用 phonegap 学习 angularJS,我有一个简单的 HTML 代码和几行 angularjs 代码。在浏览器中一切正常,但当我尝试在我的 Android 手机上运行它时,只有 HTML 代码在 phonegap 中工作。为什么?

<!DOCTYPE html>
<html>
<script src="C:\Users\Ghaith Haddad\Desktop\learning\learn\angular-1.5.8"></script>

    <script src="C:\Users\Ghaith Haddad\Desktop\learning\learn\www\me.js"></script>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title>AngularJS Tutorial</title>
    </head>
    <body>
        <script type="text/javascript" src="cordova.js"></script>
         <div ng-app="app3" ng-controller="ctrl1">
      <span>Values:</span>


      <input type="text" ng-model="first" />
      <input type="text" ng-model="second" />

      <h1>hello there buddy</h1>
      <button ng-click="update()">Sum</button>
      <br><br>


      {{calculation}}
     </div>

 <script>
        var app = angular.module('app3', []);

    app.controller('ctrl1', function($scope) {

    $scope.first = 1;
    $scope.second = 2; 

    $scope.update = function(){

        $scope.calculation = (+$scope.first + +$scope.second);
    };
    });
    <!-- Load the AngularJS library -->
    </script>

    <!-- Load the JS Module -->
    </body>
</html>

这里是JS代码:

    var app = angular.module('app3', []);

    app.controller('ctrl1', function($scope) {

$scope.first = 1;
$scope.second = 2; 

$scope.update = function(){

    $scope.calculation = (+$scope.first + +$scope.second);
};
});

【问题讨论】:

  • 由于某种原因它没有显示前几行,它也有这个:
  • 我认为您的手机无法访问您的工作站硬盘 -> C:\Users\Ghaith Haddad\Desktop\learning\learn\www\me.js & C:\Users\Ghaith Haddad\Desktop\learning\learn\angular-1.5.8 ;-)
  • 我明白了,你知道我该如何解决这个问题吗?谢谢

标签: javascript html angularjs phonegap-build phonegap


【解决方案1】:

cordova 使用相对路径(如“./”)而不是绝对路径( ),这就是脚本无法加载的方式。无论如何,您可以使用 chrome 在 android 中调试您的解决方案,并使用 safari 检查器连接设备或 iOS。

例子:

<!DOCTYPE html>
<html>
  <head>
    <base href=".">
  </head>
  <body>
    <script type="text/javascript" src="bundle.js"></script>
  </body>
</html>

【讨论】:

  • 有一个基本的例子。 src 应该与此文件的正确路径匹配。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-16
  • 2022-12-25
  • 1970-01-01
  • 1970-01-01
  • 2023-04-09
相关资源
最近更新 更多