在Ionic中激活状态

时间:2016-05-06 20:11:02

标签: angularjs cordova ionic-framework

我想在我的项目中添加一个侧边菜单,所以我将 menu.html 添加到我的模板中,并在我的 app.js 中添加了一个状态:

.state('app', {
    url: '/menu',
    templateUrl: 'templates/menu.html',
    controller: 'menuCtrl'
  })

 .state('ListeUsers', {
    url: '/ListeUsers',
    views: {
        'menuContent': {
          templateUrl: 'templates/ListeUsers.html',
          controller: 'UsersCtrl'
        }
      }

  });


  $urlRouterProvider.otherwise('/ListeUsers');

`

我的 index.html 正文:

<body ng-app="starter" > <ion-nav-view> </ion-nav-view> </body>

启动项目时,状态 app 似乎未激活。 当我启用服务器日志输出时,我最后得到这个:

enter image description here

SOLUTION:

要解决此问题,我必须将 ListeUsers 定义为 app 的孩子,以便 app.js 变成这样:

app.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider

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

  .state('app.ListeUsers', {
    url: '/ListeUsers',
    views: {
        'menuContent': {
          templateUrl: 'templates/ListeUsers.html',
          controller: 'UsersCtrl'
        }
      }

  });


  $urlRouterProvider.otherwise('/app/ListeUsers');
});

1 个答案:

答案 0 :(得分:0)

默认情况下,您应该执行此操作或更多信息,并在下面提供链接。

$urlRouterProvider.otherwise('/menu');

https://scotch.io/tutorials/angular-routing-using-ui-router