Angular UI Router:默认嵌套视图

时间:2015-07-21 17:43:05

标签: javascript angularjs angular-ui-router

我有以下内容:

.state('account', {
    abstract: true,
    url: '/account',
    templateUrl: 'pages/templates/account.html',
    controller: 'account'
})

.state('account.settings', { 
    url: '/settings', 
    templateUrl: 'pages/templates/account.settings.html', 
    controller: 'account.settings'
})

.state('account.user', { 
    url: '/user', 
    templateUrl: 'pages/templates/account.user.html', 
    controller: 'account.user'
})

如果我去,我正试图这样做:

/account => it goes to /account/settings
/account/setting => goes to /account/settings
/account/user => goes to /account/user

基本上将account.setting设为默认值。

有办法做到这一点吗?

我想这样做的一个重要原因是因为以下内容(也许有人对解决方案有更好的建议)

我有这样的链接:

<a ui-sref="account.settings" ui-sref-active="active">Account<a>

无论嵌套视图(设置或用户)是什么,我都希望它具有active类。但我希望此链接始终将用户发送到account.settings

如果有人能帮助我,我们将不胜感激。

1 个答案:

答案 0 :(得分:0)

尝试:

<table class="OrderNumber" style="width:100%">
    <thead>
        <tr></tr>
        <tr>
            <td>Order Number</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>234456667</td>
        </tr>
        <tr></tr>
    </tbody>
</table>
<br></br>
<table class="OrderDetail" style="width:100%">
    <thead>
        <tr>
            <th>Line Item Number</th>
            <th>Item Description</th>
            <th>Ship To Location</th>
            <th>Carrier</th>
            <th>Tracking Number</th>
        </tr>
    </thead>
    <tbody>
        <tr class="separating_line">
            <td>1</td>
            <td>$itemDescription</td>
            <td>$shipToLocation</td>
            <td>$carrier</td>
            <td style="color:#33CCFF">$trackingNumber</td>
        </tr>
        <tr class="separating_line">
            <td>1</td>
            <td>$itemDescription</td>
            <td>$shipToLocation</td>
            <td>$carrier</td>
            <td style="color:#33CCFF">$trackingNumber</td>
        </tr>
    </tbody>
</table>

或者从抽象重定向到具体状态......代码段会删除指定的“帐户”控制器引用,但如果需要,可以将代码段中的代码添加到控制器中:

.state('account', {
    abstract: true,
    url: '/account',
    templateUrl: 'pages/templates/account.html',
    controller: 'account'
})
.state('account.settings', { 
    url: '', 
    templateUrl: 'pages/templates/account.settings.html', 
    controller: 'account.settings'
})

.state('account.settings2', { 
    url: '/settings', 
    templateUrl: 'pages/templates/account.settings.html', 
    controller: 'account.settings'
})

.state('account.user', { 
    url: '/user', 
    templateUrl: 'pages/templates/account.user.html', 
    controller: 'account.user'
})