0

androidでangularjsとphonegapを使用して基本的なアプリを作成しようとしています。しかし、それは機能していないようです。以下は私のソースコードファイルです:

index.html

    <!DOCTYPE html>
<html ng-app="main-app">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Insert title here</title>
</head>
<body>
<div class="body-content" ng-controller="MainCtrl">
    <div class="loader-ajax" ng-show="isViewLoading"></div>
    <div ng-view></div>
</div>
    <script src="js/angular.js"></script>
    <script type="text/javascript" src="js/main.js"></script>
    <script type="text/javascript" src="cordova-2.3.0.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
            app.initialize();
    </script>
</body>
</html>

main.js

var mobileApp = angular.module("main-app", []);

mobileApp.config(function ($routeProvider,$compileProvider) {

    $routeProvider
        .when("/",
        {
            templateUrl: "partial/home.html",
            controller: "homeController"
        })
        .when("/home",
        {
            templateUrl: "partial/home.html",
            controller: "homeController"
        });
    $compileProvider.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel):/);
});
mobileApp.controller("MainCtrl",function($scope){
    alert('Coming here');
    $scope.isViewLoading=true;
});
mobileApp.controller("homeController",function($scope){
    alert('Home Coming here');

});

index.js

var app = {
    initialize: function() {
        this.bind();
    },
    bind: function() {
        document.addEventListener('deviceready', this.deviceready, false);
    },
    deviceready: function() {
        // note that this is an event handler so the scope is that of the event
        // so we need to call app.report(), and not this.report()
        app.report('deviceready');
        angular.bootstrap(document, ['main-app']);
    },
    report: function(id) { 
        console.log("report:" + id);
    }
};

アプリが読み込まれると、ルーターがHomecontrollerに接続されないため、ルーターが機能していないように見えます。

私が他のどこでも準備したものから、このコードは機能するはずです。どんな助けでも大歓迎です。

4

3 に答える 3

2

私は同じ問題を抱えていましたが、それに対する解決策を見つけました。PhoneGapで機能しないAngularng-view/routingを見てください

于 2013-03-26T21:58:53.037 に答える
0

PhoneGapのdevicereadyイベントに移動 app.initialize();します

于 2013-03-26T02:19:16.327 に答える
0

私はこの問題を抱えていました-私は3晩それで立ち往生しました-最終的に私はルーティングのテンプレート名を実際のファイル名と比較しました-ケースが一致することを確認します。

于 2015-07-16T19:13:16.477 に答える