为什么我的AngularJS视图不会在Cordova中加载?

Sha*_*oon 3 javascript ios angularjs cordova

index.html是:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Hello World</title>
  </head>
  <body ng-app="app">
    THIS WORKS NOW!
    <div ng-view></div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/angular.min.js"></script>
    <script type="text/javascript" src="js/angular-route.min.js"></script>
    <script type="text/javascript" src="js/app.js"></script>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

app.js,我有:

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

app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
    $routeProvider.when('/', {
      templateUrl: 'templates/home.html'
    }).when('/dashboard', {
      templateUrl: '/templates/dashboard.html'
    }).otherwise({
      redirectTo: '/'
    });

    $locationProvider.html5Mode(true);
  }
]);
Run Code Online (Sandbox Code Playgroud)

所以我跑了cordova build ios,制作一个xcode项目真是太神奇了,然后我打开并运行它.我明白了THIS WORKS NOW!,但是我没有看到我home.html文件的内容.

我究竟做错了什么?

eza*_*ain 5

你需要bootstrap angular:

app.js 很好!

但是ng-app在标签内部移除并在触发<body>事件时开始角度onDeviceReady:

index.js 文件:

var app = {
    initialize: function () {
        this.bindEvents();
    },
    bindEvents: function () {
        document.addEventListener("deviceready", this.onDeviceReady, false);
    },
    onDeviceReady: function () {
        angular.element(document).ready(function () {

            angular.bootstrap(document, ["app"]);

        });
    }
};
Run Code Online (Sandbox Code Playgroud)

通常这就是你需要做的.