gpt4 book ai didi

javascript - 为什么我的 AngularJS View 无法在 Cordova 中加载?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:22:01 24 4
gpt4 key购买 nike

我的 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>

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);
}
]);

所以我运行 cordova build ios 并且创建一个 xcode 项目非常神奇,然后我打开并运行它。我看到 THIS WORKS NOW!,但我没有看到我的 home.html 文件的内容。

我做错了什么?

最佳答案

你需要引导 Angular :

app.js很好!

但删除ng-app在标签内 <body>并在事件 onDeviceReady 时开始 Angular 已被触发:

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"]);

});
}
};

通常这就是您需要做的所有事情。

关于javascript - 为什么我的 AngularJS View 无法在 Cordova 中加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23786382/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com