IONIC中的Angularjs,抽象路线

时间:2016-09-06 03:25:27

标签: javascript angularjs ionic-framework angular-ui-router js-routes

我正在尝试在IONIC中学习抽象路线。但是我的代码中存在问题。路线上有错误,但项目结构。有谁知道检查?

MY FILE ROUTES.JS

angular.module('starter')
    .config(function($stateProvider, $urlRouterProvider){

    $urlRouterProvider.otherwise("/menu/listagem");
    $stateProvider


    .state("menu",{
        url:"/menu",
        templateUrl:'templates/menu.html',
        abstract:true,
        controller:'listagemController'
    })

     .state("menu.listagem", {
        url: '/listagem', 
        views:{
            'menuContent':{
                templateUrl:'templates/listagem.html'
            }
        }

     });ngular.module('starter')
    .config(function($stateProvider, $urlRouterProvider){

    $urlRouterProvider.otherwise("/menu/listagem");
    $stateProvider


    .state("menu",{
        url:"/menu",
        templateUrl:'templates/menu.html',
        abstract:true,
        controller:'listagemController'
    })

     .state("menu.listagem", {
        url: '/listagem', 
        views:{
            'menuContent':{
                templateUrl:'templates/listagem.html'
            }
        }

     });

MY FILE menu.html

<ion-side-menus enable-menu-with-back-views="true">

    <ion-side-menu-content>

        <ion-nav-bar class="bar-positive">
            <ion-nav-back-button>
            </ion-nav-back-button>

            <ion-nav-buttons side="left">
                <button class="button button-clear button-icon light ion-navicon" menu-toggle="left"></button>
            </ion-nav-buttons>
        </ion-nav-bar>

        <ion-nav-view name="menuContent"></ion-nav-view>
    </ion-side-menu-content>

    <ion-side-menu side="left">

    <ion-header-bar class="bar-positive">
        <h1 class="title">Menu</h1>
    </ion-header-bar>

        <ion-content>

        <ion-list>
            <ion-item href="#/menu/home" menu-close>Home</ion-item>
            <ion-item href="#/menu/login" menu-close>Login</ion-item>
            <ion-item href="" menu-close>Sair</ion-item>
        </ion-list>

        </ion-content>

    </ion-side-menu>

</ion-side-menus>

MY FILE listagem.html

   <ion-view>

<ion-nav-title>Plantas Medicinais</ion-nav-title>

<ion-content>

<h1="title">SUCESS</h1>


</ion-content>  

</ion-view>

1 个答案:

答案 0 :(得分:0)

在ROUTE.JS

中尝试此操作
angular.module('starter', ['ionic'])
.config(function($stateProvider, $urlRouterProvider,$httpProvider) {

   $httpProvider.defaults.headers.common = {};
  $httpProvider.defaults.headers.post = {};
  $httpProvider.defaults.headers.put = {};
  $httpProvider.defaults.headers.patch = {};
  $stateProvider
    .state('menu', {
      url: "/menu",
      abstract: true,
      templateUrl: "templates/menu.html",
      controller: 'listagemController'
    })

    .state('menu.listagem', {
      url: "/listagem",
      views: {
        'menuContent' :{
          templateUrl: "templates/listagem.html"
        }
      }
    })

  $urlRouterProvider.otherwise('/menu/listagem');
});

In MENU.HTML write 

<ion-side-menus>
  <ion-side-menu-content>
    <ion-nav-bar class="bar-light nav-title-slide-ios7">
      <ion-nav-back-button class="button-clear"><i class="icon ion-ios7-arrow-back"></i> Back</ion-nav-back-button>
    </ion-nav-bar>
    <ion-nav-view name="menuContent" animation="slide-left-right"></ion-nav-view>
  </ion-side-menu-content>
  <ion-side-menu side="left">   
    <ion-content class="gem-sidebar dark">
        <ion-list>
            <ion-item href="#/menu/home" menu-close>Home</ion-item>
            <ion-item href="#/menu/login" menu-close>Login</ion-item>
            <ion-item href="" menu-close>Sair</ion-item>
        </ion-list>          
    </ion-content>
  </ion-side-menu>
</ion-side-menus>