2015-10-13 39 views
0

我想在我的項目上使用ui-router。angularjs - ui.router不立即渲染ui-view

核心模塊:

var core = angular.module('muhamo.core', ['angular-loading-bar', 'anguFixedHeaderTable', 'ui.router']); 

跟蹤模塊:

var app = angular.module(TRACKING_MODULE_NAME, ['muhamo.core']); 
    app.config(Configure); 

Configure.$inject = ['$stateProvider', '$urlRouterProvider']; 
function Configure($stateProvider, $urlRouterProvider) { 
    $stateProvider.state('contacts', { 
     templateUrl: '/static/partials/employee/employee-edit', 
     controller: function() { 
      this.title = 'My Contacts'; 
     }, 
     controllerAs: 'contact' 
    }); 
    $urlRouterProvider.otherwise("/contacts"); 
    console.log($stateProvider); 
} 

和HTML定義:

<div ui-view></div> 

如果我點擊一個UI的SREF鏈接它工作正常。但在頁面加載時,它不會加載默認視圖「/ contacts」。我在這裏錯過了什麼嗎?

UPDATE

它可以添加缺失 「URL」 屬性之後。但現在我已經另外一個問題,如果我延長我實現這樣的:

function Configure($stateProvider, $urlRouterProvider) { 
     $stateProvider.state('employees', { 
      abstract: true, 
      url: "/employees" 
      /* Various other settings common to both child states */ 
     }).state('employees.list', { 
      url: "", // Note the empty URL 
      templateUrl: '/static/partials/employee/employee-list' 
     }); 
    $urlRouterProvider.otherwise("/employees"); 
    console.log($stateProvider); 
} 

還與多個國家,UI的觀點並沒有渲染。

回答

1

有在實施兩個由腥的東西。你出了一個空的url,你的默認路由是抽象的。在下面嘗試我的更改。

function Configure($stateProvider, $urlRouterProvider) { 
    $stateProvider.state('employees', { 
     abstract: true, 
     url: "/employees" 
     /* Various other settings common to both child states */ 
    }).state('employees.list', { 
     url: "/list", // Note the empty URL 
     templateUrl: '/static/partials/employee/employee-list' 
    }); 
$urlRouterProvider.otherwise("/employees/list"); 
console.log($stateProvider); 

乾杯

1

是的。您需要將state.url設置爲'/聯繫人的

$stateProvider.state('contacts', { 
    url: '/contacts', 
    templateUrl: '/static/partials/employee/employee-edit', 
    controller: function() { 
     this.title = 'My Contacts'; 
    }, 
    controllerAs: 'contact' 
}); 
+0

可以請你來看看我的更新問題? – aymeba

+0

我不認爲你可以有一個空的網址。但是,你可以有一個「/」網址,並添加一個'$ urlRouterProvider.when('/ employees','/ employees /');' –

1

看來你忘了設置url參數,例如:

$stateProvider.state('contacts', { 
    url: "/contacts", 
    ... 
} 
+0

它現在可以工作了,謝謝:)有時我們需要更多的咖啡:) – aymeba

+0

你能看看我更新的問題嗎? – aymeba

+0

基本上,如果要使用具有空URL的嵌套狀態,則需要父狀態中的調度程序。請參閱[我對另一個問題的答案的第二部分](http://stackoverflow.com/a/32712889/18745)。 – DzinX