2013-03-26 84 views
0

我想在android中使用angularjs和phonegap基本應用程序。但它似乎並沒有工作。下面是我的源代碼文件:角度ng視圖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,所以似乎不起作用。

從我已經準備好的其他地方,這段代碼應該可以工作。任何幫助將不勝感激。

+1

http://briantford.com/blog/angular-phonegap.html – 2013-03-26 15:42:57

+0

@SimonMacDonald嘿男子我試過這個教程,並由於某種原因它沒有工作(亞曼說明哪裏種過時?)..無論如何,你知道任何github回購或類似的,完成phonegap/angularjs項目?那將是一個很好的開始! – abbood 2013-06-14 12:41:33

回答

0

我有這個問題 - 我被困在它3晚 - 最終我將路由中的模板名稱與實際文件名進行比較 - 確保大小寫匹配。