1

我目前Angular UI-Router 0.0.2在我的角度应用程序中使用路由/状态。在我的应用程序中,我有一个仪表板和一个帐户页面——仪表板显示应用程序数据;帐户页面显示用户信息。

当我将dashboardandaccount状态作为两个独立的状态时,路由会发生变化,并且会显示帐户页面。

此代码有效:

routes = app.config ($stateProvider, $urlRouterProvider) ->

$urlRouterProvider.otherwise '/'

$stateProvider.state( 'dashboard',
  url: '/'
  templateUrl: "app/views/dashboard/index.html"
  controller: 'DashboardIndexCtrl'
).state( 'account'
  url: '/account'
  templateUrl: "app/views/account/index.html"
  controller: 'AccountIndexCtrl'
)

但是,每当我将account状态设置为 的嵌套状态时dashboard,只会显示一个空白屏幕。

此代码不起作用:

routes = app.config ($stateProvider, $urlRouterProvider) ->

$urlRouterProvider.otherwise '/'

$stateProvider.state( 'dashboard',
  url: '/'
  templateUrl: "app/views/dashboard/index.html"
  controller: 'DashboardIndexCtrl'
).state( 'dashboard.account'
  url: 'account'
  templateUrl: "app/views/account/index.html"
  controller: 'AccountIndexCtrl'
)

我的dashboard/index.html文件:

%section.row-fluid
  .span12
    / directive
    %loginform

loginform的指令模板:

loginFormCtrl = app.controller 'LoginFormCtrl', ($scope, $rootScope, $location, $state, $log, User, Session) ->

  $rootScope.logged_in = false

  User.current().$promise.then (success) ->
    $log.info success
    $rootScope.current_user = success.user
    $rootScope.logged_in = true if success.user.user_name != null
4

1 回答 1

5

ui-view在您的仪表板/index.html 模板中添加一个。

于 2013-08-19T22:29:50.477 回答