2016-04-30 92 views
1

我正在使用科尔多瓦建设一个android应用。我正在使用angularjs ui-router进行路由。 ui-sref完全不起作用。下面是我的代码:ui-sref不工作在科尔多瓦android应用

var angularApp = angular.module('angularApp', [ 
    'ui.router', 
    'ngTouch', 
    'angular.filter', 
    'angularApp.services', 
    'angularApp.controller', 
]); 

angularApp.config(function($stateProvider, $locationProvider, $urlRouterProvider) { 
    $stateProvider 
    .state('home', { 
     url: '/home', 
      templateUrl: 'templates/home.html', 
    }) 
    .state('settings', { 
     url: '/settings', 
      templateUrl: 'templates/settings.html', 
    }); 
    $urlRouterProvider.otherwise('/home'); 
    }); 

在家状态加载默认情况下,当我点击链接的设置上,它无法正常工作。

下面是index.html中的代码

<!DOCTYPE html> 
<!-- 
    Licensed to the Apache Software Foundation (ASF) under one 
    or more contributor license agreements. See the NOTICE file 
    distributed with this work for additional information 
    regarding copyright ownership. The ASF licenses this file 
    to you under the Apache License, Version 2.0 (the 
    "License"); you may not use this file except in compliance 
    with the License. You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0 

    Unless required by applicable law or agreed to in writing, 
    software distributed under the License is distributed on an 
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
    KIND, either express or implied. See the License for the 
    specific language governing permissions and limitations 
    under the License. 
--> 
<html> 
    <head> 
     <!-- 
     Customize this policy to fit your own app's needs. For more guidance, see: 
      https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy 
     Some notes: 
      * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication 
      * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly 
      * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: 
       * Enable inline JS: add 'unsafe-inline' to default-src 
     --> 
     <!-- <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> --> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <meta name="description" content=""> 
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui"> 
     <meta name="format-detection" content="telephone=no"> 
     <link rel="stylesheet" type="text/css" href="css/index.css"> 
     <link rel="stylesheet" href="css/custom.css"> 
     <link rel="stylesheet" href="css/icomoon.css"> 
     <!-- Path to Framework7 Library CSS--> 
     <link rel="stylesheet" href="lib/framework7/css/framework7.material.min.css"> 
     <link rel="stylesheet" href="lib/framework7/css/framework7.material.colors.min.css"> 
     <base href="file:///android_asset/www/" target="_blank"> 
    </head> 
    <body> 
     <script type="text/javascript" src="lib/angular/angular.min.js"></script> 
     <script type="text/javascript" src="lib/angular/angular-ui-router.js"></script> 
     <script type="text/javascript" src="lib/angular/angular-filter.min.js"></script> 
     <script type="text/javascript" src="lib/angular/angular-touch.min.js"></script> 
     <script type="text/javascript" src="js/angularjs-app.js"></script> 
     <script type="text/javascript" src="lib/framework7/js/framework7.min.js"></script> 
     <div id="welcome-wrap"> 
      <div class="logo"><img src="img/logo.png"/></div> 
      <div class="preloader"></div> 
     </div> 

     <div ng-include="'templates/common-left-panel.html'"></div> 

     <div class="views"> 
      <!-- Your main view, should have "view-main" class--> 
      <div class="view view-main"> 
       <div class="navbar"> 
        <div class="navbar-inner"> 
         <div class="left"> 
          <a href="#" class="link icon-only open-panel"> <i class="icon icon-navicon"></i></a> 
         </div> 
         <div class="center"> 
          <h3>app</h3> 
         </div> 
         <div class="right"> 
          <a href="#" class="link icon-only search-icon"> <i class="icon icon-search"></i></a> 
          <a ui-sref="settings" class="link icon-only setting-icon"> <i class="icon icon-gear"></i></a> 
         </div> 
        </div> 
       </div> 
       <!-- Main page content with bottom tab bar --> 
       <div class="pages navbar-fixed"> 
       <a href="#/settings">Settings</a> 
        <div ui-view></div> 
       </div> 
      </div> 
     </div> 

     <script type="text/javascript" src="cordova.js"></script> 
     <script type="text/javascript" src="js/framework-app.js"></script> 
     <script type="text/javascript" src="js/controllers.js"></script> 
     <script type="text/javascript" src="js/services.js"></script> 
    </body> 
</html> 
+0

您是否正在设置ng-app属性?例如:__ __ –

+0

我实际上在cordova deviceready事件上引导角度。 angular.bootstrap(document,['angularApp']); },false); 还不够? –

+0

它应该工作。可以肯定的是,把一个__console.log(“test”)__放在__angularApp.config__上面,看看这个日志是否可以工作 –

回答

0

确保你在你的HTML标签headContent-Security-Policy meta元素。

事情与此类似:

<meta http-equiv="Content-Security-Policy" content="default-src * 'self' 'unsafe-inline' 'unsafe-eval' data: gap: ; connect-src * data: blob: filesystem:; font-src * 'self' filesystem: ; style-src 'self' 'unsafe-inline'; media-src * 'self' filesystem: ; img-src * 'self' data: filesystem: ; frame-src 'self' gap://*"> 

请参阅this link对您的情况适当的安全选择更多信息。

相关问题