2015-11-08 61 views
0

我會盡量保持這一點儘可能簡單,而不會丟失問題的上下文。使用ui路由器訪問數據的狀態

假設我使用UI-路由器

$stateProvider.state("home", { 
    abstract: true, 
    templateUrl: "...", 
    meta: { 
     label: "...", 
     ... 
    } 
}); 

如何訪問當前狀態的meta對象的屬性和值,這樣我可以在視圖中應用這些,例如有一個狀態:

<section class="content-header"> 
    <h1> 
     {{meta.label}} 
    </h1> 
</section> 

因此,上述示例將顯示當前狀態的meta對象的值label

+0

https://github.com/angular-ui/ui-router/wiki#attach-custom -data到狀態的對象 – o4ohel

回答

0

ui-router doc,你應該能夠通過注入$狀態,以此來訪問它:

$state.current.meta.label