WindowsPhone 8(phonegap)和AngularJs - $ routeProvider不工作?

时间:2014-04-29 07:21:24

标签: javascript angularjs cordova windows-phone-8 windows-phone-8-emulator

我的思绪消失了。我不知道我的代码有什么问题。

嗯,我会为此解释一下。

档案详情:

Cordova 2.9.1版本

angularjs 1.2.13版本(也使用了最新版本(1.2.16)的所有版本)

我使用的是Windows Phone 8 App

这是我的代码

App.js

'use strict';
window.myApp = angular.module('myApp', ['ajoslin.mobile-navigate', 'ngMobile',
    'myApp.Registermdl',
   'myApp.login', 'myApp.CreateUsermdl', 'myApp.viewMap', 'myApp.createMap',
'myApp.logout', 'ngProgress', 'ngCookies','ngRoute'])


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

    $compileProvider.aHrefSanitizationWhitelist(/^\s*(http?|ftp|mailto|file|tel):/);

    $routeProvider.when('/', { templateUrl: 'index.html', controller: 'IndexCtrl' });
    $routeProvider.when('/login', { templateUrl: 'app/login/login.html', controller: 'LoginCtrl' });
    $routeProvider.when('/home', { templateUrl: 'app/home/home.htm', controller: 'HomeCtrl' });
    $routeProvider.when('/createuser', { templateUrl: 'app/CreateUser/createUser.html', controller: 'CreateUserCtrl' });
    $routeProvider.when('/signup', { templateUrl: 'app/register/register.html', controller: 'RegisterCtrl' });
    $routeProvider.when('/logout', { templateUrl: 'app/login/login.html', controller: 'LogoutCtrl' });
    $routeProvider.when('/view-map', { templateUrl: 'app/ViewMap/viewmap.html', controller: 'ViewMapCtrl' });
    $routeProvider.when('/create-map', { templateUrl: 'app/CreateMapAddress/create-mapaddress.html', controller: 'CreateMapAddressCtrl' });
    $routeProvider.otherwise({ redirectTo: '/' });
});

myApp.controller('IndexCtrl', ['$rootScope', '$scope', '$location', '$route', '$cookieStore', '$cookies',
    function ($rootScope, $scope, $location, $route, $cookieStore, $cookies) {
        if ($cookieStore.get('userEmail') == undefined) {
            $rootScope.IsLogin = false;
            $rootScope.IsLogout = true;
            $rootScope.IsAdmin = false;
            $rootScope.userName = "";
            $scope.$apply();
            if ($location.$$path == "/signup") {
                $location.$$path = "/signup";
                $route.reload();
                return false;
            }
            $location.$$path = "/login";
            $route.reload();
            alert("goos Start5");
            return false;
        }
        $rootScope.IsAdmin = false;
        if ($cookieStore.get('userRole') == "Admin") {
            $rootScope.IsAdmin = true;
        }
        $rootScope.IsLogin = true;
        $rootScope.IsLogout = false;
        $rootScope.userName = $cookieStore.get('userEmail');
        $route.reload();

    }]);
//var hostname = 'qbsnewsvr/CollegeApp';
var hostname = 'localhost:54938/';
var rootUrl = 'http://' + hostname;

和索引页面(主页)

<!DOCTYPE html>
<html xmlns:ng="http://angularjs.org" lang="en" ng-app="myApp">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Use the .min version of bootstrap files in production -->
    <!-- Use the following if you want to use responsive design -->
    <link rel="stylesheet" type="text/css" href="dist/css/bootstrap-custom.css">
    <link rel="stylesheet" type="text/css" href="dist/css/toastr.min.css">
    <!-- Custom styles for this template -->
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Scripts begins-->

    <script src="assets/js/jquery.min.js"></script>
    <script src="dist/js/bootstrap.js"></script>
    <script src="assets/js/offcanvas.js"></script>
    <link href="css/MSDList.css" rel="stylesheet" />
</head>

<body>
    <!-- The following tag is in place of ng-view to use the angular mobile view navigation framework
            https://github.com/ajoslin/angular-mobile-nav
        -->
    <div class="navbar navbar-default navbar-fixed-top" role="navigation" ng-controller="IndexCtrl">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">College App</a>
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="#/home">Home</a></li>
                    <li><a href="#/home">Contact</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            <li>
                                <form class="navbar-form" role="search">
                                    <div class="input-group">
                                        <input type="text" class="form-control input-sm" placeholder="Search" name="srch-term" id="srch-term">
                                        <div class="input-group-btn">
                                            <button class="btn btn-default btn-sm" type="submit"><i class="glyphicon glyphicon-search"></i></button>
                                        </div>
                                    </div>
                                </form>
                            </li>
                            <li class="divider"></li>
                            <li class="dropdown-header">Nav header</li>
                            <li><a href="#/home">Separated link</a></li>
                            <li><a href="#/home">One more separated link</a></li>
                        </ul>
                    </li>
                </ul>
                <div ng-show="IsLogin">
                    <p class="navbar-text welocome-aliginment">Welcome <a href="#" class="wecome-text" id="welcomeName">{{userName}}</a></p>
                </div>
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="#/login" ng-show="IsLogout">Login</a></li>
                    <li><a href="#/signup" ng-show="IsLogout">SignUp</a></li>
                    <li><a href="#/createuser" ng-show="IsLogin && IsAdmin">Create New User</a></li>
                    <li class="active" ng-show="IsLogin"><a href="#/view-map">View Map</a></li>
                    <!-- <li class="active" ng-show="IsLogin"><a href="#/create-map">Create Map</a></li>-->
                    <li class="active" ng-show="IsLogin"><a href="#/logout">Logout</a></li>
                </ul>
            </div>
            <!--/.nav-collapse -->
        </div>
    </div>
    <div class="container" ng-view></div>
    <!-- Comment out the following 2 lines to test on the browser-->
    <script type="text/javascript" src="cordova.js"></script>

    <!-- In production use min versions -->
    <script src="js/q.js"></script>
    <script src="lib/angular/jx.min.js"></script>
    <script src="lib/angular/angular.js"></script>
    <script src="lib/angular/angular-route.js"></script>
    <script src="lib/angular/angular-mobile.js"></script>
    <script src="lib/angular/mobile-nav.js"></script>
    <script src="lib/angular/angular-cookies.min.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <!-- 3rd party libraries -->
    <script src="js/toastr.min.js"></script>
    <script src="lib/ngProgress/ngProgress.min.js"></script>
    <script src="lib/MSDList.js"></script>

    <!-- app js -->
    <!-- <script src="http://maps.google.com/maps?file=api&v=3&key=AIzaSyBbd_4N1j8WIoRJ0trcrqGLlo0a6T_e-bA"></script>-->
    <!-- <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&amp;ver=3.5.1"></script>-->

    <!-- <script src="lib/Clusterer2.js"></script>-->
    <!-- controller  -->
    <script src="js/app.js"></script>
    <script src="app/home/home.js"></script>
    <script src="app/register/register.js"></script>
    <script src="app/CreateUser/createUser.js"></script>
    <script src="app/login/login.js"></script>
    <script src="app/ViewMap/viewmap.js"></script>
    <script src="app/Login/logout.js"></script>
    <script src="app/CreateMapAddress/create-mapaddress.js"></script>
    <!-- logger -->
    <script src="js/logger.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>
</body>
</html>

我的代码在所有浏览器上运行良好。但只是没有在模拟器中工作。我尝试过很多方法。

我从Stack溢出中得到了一些答案

有配置此行

$compileProvider.aHrefSanitizationWhitelist(/^\s*(http?|ftp|mailto|file|tel):/);

但我已经这样做了。一切正常。但是$routeProvider在模拟器中不起作用。(这意味着页面不会重定向到索引页面)。

我不知道。这是一个版本问题或任何冲突问题等...

任何人请帮助我

1 个答案:

答案 0 :(得分:2)

为窗口移动应用添加&#34; ms-appx&#34;修复angularjs路由。 for unsafe:ms-appx://。

$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|file|ms-appx):/)