angular ng-view phonegap 不起作用 [英] angular ng-view phonegap is not working

查看:23
本文介绍了angular ng-view phonegap 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 android 中使用 angularjs 和 phonegap 制作基本应用程序.但它似乎不起作用.以下是我的源代码文件:

index.html

 <html ng-app="main-app"><头><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>在此处插入标题</title><身体><div class="body-content" ng-controller="MainCtrl"><div class="loader-ajax" ng-show="isViewLoading"></div><div ng-view></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();</html>

main.js

var mobileApp = angular.module("main-app", []);mobileApp.config(function ($routeProvider,$compileProvider) {$routeProvider.什么时候("/",{templateUrl: "partial/home.html",控制器:家庭控制器"}).when("/家",{templateUrl: "partial/home.html",控制器:homeController"});$compileProvider.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel):/);});mobileApp.controller("MainCtrl",function($scope){alert('来到这里');$scope.isViewLoading=true;});mobileApp.controller("homeController",function($scope){alert('到家了');});

index.js

var app = {初始化:函数(){this.bind();},绑定:函数(){document.addEventListener('deviceready', this.deviceready, false);},设备就绪:函数(){//注意这是一个事件处理程序,所以作用域是事件的作用域//所以我们需要调用 app.report(),而不是 this.report()app.report('设备就绪');angular.bootstrap(document, ['main-app']);},报告:功能(ID){console.log("报告:" + id);}};

当应用加载时,路由器似乎无法工作,因为它没有进入 Homecontroller.

从我在其他地方准备好的内容来看,这段代码应该可以工作.任何帮助将不胜感激.

解决方案

我遇到了同样的问题,我刚刚找到了解决方案.看看 Angular ng-view/routing 在 PhoneGap 中不起作用

I am trying to make basic app with angularjs and phonegap in android. But it doesn't seem to be working. Below are my source code files:

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

When the app is getting load, router doesn't seem to work as its not getting into Homecontroller.

From what I have ready everywhere else, this code should work. Any help would be greatly appreciated.

解决方案

I had the same problem, which I just found a solution to. Take a look at Angular ng-view/routing not working in PhoneGap

这篇关于angular ng-view phonegap 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆