3

我遇到了一个我想在离子中迁移的角度应用程序的问题

我将 ui-router 用于角度,这是我的 app.js(在此处拍摄:https ://github.com/tarlepp/angular-sailsjs-boilerplate-frontend/blob/master/src/app/app.js )。我没有为我的项目对这个文件进行任何更改

现在我想为我的项目重用这个文件,所以我用这个替换了 ionic 给出的 app.js 并添加了

  $ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
  StatusBar.styleDefault();
}});

在 app.run 里面

这是我的 index.html :

    <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="frontend">
<ion-pane>
  <ion-header-bar class="bar-stable">
    <h1 class="title">Ionic Blank Starter</h1>
  </ion-header-bar>
  <ion-content>
  </ion-content>
</ion-pane>
</body>
</html>

我只是用前端替换了 ng-app 的名称,而离子主题没有正确收费。

我不知道问题是来自 ui-retour 依赖还是其他原因?我想我错过了什么

注意:我知道我必须更改项目的 html 和 css 文件,但是对于 index.html,我只有 ionic 提供的内容,并且我没有带有“ionic blank starter”的 ionic 选项卡,就像我一样开始一个空白的离子项目

这是我的路由器更改:

enter code here
(function() {
'use strict';



 angular.module('frontend', [
'ionic',
'frontend-templates',
'frontend.core',
'frontend.myportfolio',
'frontend.mysocial',
'frontend.myleads',
'frontend.admin'
  ]);

 angular.module('frontend')
 .config([
  '$stateProvider', '$locationProvider', '$urlRouterProvider',      '$httpProvider', '$sailsSocketProvider',
  '$tooltipProvider', 'cfpLoadingBarProvider',
  'toastrConfig',
  'AccessLevels',
  function config(
    $stateProvider, $locationProvider, $urlRouterProvider,   $httpProvider, $sailsSocketProvider,
    $tooltipProvider, cfpLoadingBarProvider,
    toastrConfig,
    AccessLevels
  ) {



    $httpProvider.defaults.useXDomain = true;

    delete $httpProvider.defaults.headers.common['X-Requested-With'];

    // Add interceptors for $httpProvider and $sailsSocketProvider
    $httpProvider.interceptors.push('AuthInterceptor');
    $httpProvider.interceptors.push('ErrorInterceptor');

    // Iterate $httpProvider interceptors and add those to $sailsSocketProvider
    angular.forEach($httpProvider.interceptors, function iterator(interceptor) {
      $sailsSocketProvider.interceptors.push(interceptor);
    });

    // Set tooltip options
    $tooltipProvider.options({
      appendToBody: true
    });

    // Disable spinner from cfpLoadingBar
    cfpLoadingBarProvider.includeSpinner = false;
    cfpLoadingBarProvider.latencyThreshold = 200;

    // Extend default toastr configuration with application specified configuration
    angular.extend(
      toastrConfig,
      {
        allowHtml: true,
        closeButton: true,
        extendedTimeOut: 3000
      }
    );

    // Yeah we wanna to use HTML5 urls!
    $locationProvider
      .html5Mode({
        enabled: true,
        requireBase: false
      })
      .hashPrefix('!')
    ;

    // Routes that needs authenticated user
    $stateProvider
      .state('profile', {
        abstract: true,
        template: '<ui-view/>',
        data: {
          access: AccessLevels.user
        }
      })



    $urlRouterProvider.otherwise('/myportfolio/mydatabase');
    }
   ])
   ;


 angular.module('frontend')
   .run([
     '$rootScope', '$state', '$injector','$ionicPlatform',
     'editableOptions',
  'AuthService',
  function run(
    $rootScope, $state, $injector,$ionicPlatform,
    editableOptions,
    AuthService
  ) {

    $rootScope.$on('$stateChangeStart', function   stateChangeStart(event, toState) {
      if (toState.url=='/login' || toState.url=='/register' ) {
        $rootScope.myStyle = {'background-color':'#333'}
        $rootScope.headerIsloaded = false;
        $rootScope.sidebarIsloaded = false;

      }else{

        $rootScope.myStyle = {};
        $rootScope.headerIsloaded = true;
        $rootScope.sidebarIsloaded = true

      };

      if (!AuthService.authorize(toState.data.access)) {
        event.preventDefault();
        console.log(toState.data.access)

        $state.go('auth.login');
      }
    });

    // Check for state change errors.
    $rootScope.$on('$stateChangeError', function stateChangeError(event, toState, toParams, fromState, fromParams, error) {
      event.preventDefault();

      $injector.get('MessageService')
        .error('Error loading the page');

      $state.get('error').error = {
        event: event,
        toState: toState,
        toParams: toParams,
        fromState: fromState,
        fromParams: fromParams,
        error: error
      };

      return $state.go('error');
    });


    //bout de code ionic

    $ionicPlatform.ready(function() {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      if(window.cordova && window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      }
      if(window.StatusBar) {
        StatusBar.styleDefault();
      }
    });

  }
])
 ;
  }());
4

1 回答 1

0

你是不是错过了 ui.router 的标记来注入你的状态视图?

<ion-view view-title="your-view">
</ion-view>

如果你创建一个新的应用程序

ionic start myApp

它默认为tab在其 index.html 中包含以下正文的模板

  <body ng-app="starter">
    <!--
      The nav bar that will be updated as we navigate between views.
    -->
    <ion-nav-bar class="bar-stable">
      <ion-nav-back-button>
      </ion-nav-back-button>
    </ion-nav-bar>
    <!--
      The views will be rendered in the <ion-nav-view> directive below
      Templates are in the /templates folder (but you could also
      have templates inline in this html file if you'd like).
    -->
    <ion-nav-view></ion-nav-view>
  </body>

ion-nav-view就是允许 ui.router 插入其视图的原因

于 2015-09-18T08:07:18.003 回答