0

我想做这样的事情:

.state('tabs.order', {
    url: "/order/:orderId",
    views: {
        'orders-tab': {
            templateUrl: "templates/orderDetail.html",
            controller: 'OrderDetailController'
        },
        'orders-all-tab': {
            templateUrl: "templates/orderDetail.html",
            controller: 'OrderDetailController'
        }
    }
})

然后在我看来,我会放置一个有条件的 ui-sref,我可以在其中选择要处理的选项卡;像这样的东西:

ui-sref="tabs.order({orderId:order.ID}, <orders-tab or orders-all-tab?>)"

这可能吗?谢谢

4

1 回答 1

0

好吧,我认为目前还没有任何方法可以在 中指定视图ui-sref,但这是一个起点,希望对您有所帮助。

首先,路线:

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

$urlRouterProvider.otherwise("/order/all-orders");

$stateProvider
    .state("order", { abtract: true, url:"/order", templateUrl:"main.html" })
        .state("order.orderTab", { url: "/order-details", templateUrl: "orderDetails.html" })
        .state("order.orderAllTab", { url: "/all-orders", templateUrl: "allOrders.html" });
});


然后,定义您的主页(订单和订单详情)[main.html]

<div ng-controller="mainController">
    <tabset>
        <tab 
            ng-repeat="t in tabs" 
            heading="{{t.heading}}"
            select="go(t.route)"
            active="t.active">
        </tab>
    </tabset>
    <h2>View:</h2>
    <div ui-view></div>
</div>


和页面控制器指定选项卡数据:

app.controller("mainController", function($rootScope, $scope, $state) {     

    $scope.go = function(route){
        $state.go(route);
    };

    $scope.active = function(route){
        return $state.is(route);
    };

    $scope.tabs = [
        { heading: "Order", route:"order.orderTab", active:true },
        { heading: "All Orders", route:"order.orderAllTab", active:false },
    ];

    $scope.$on("$stateChangeSuccess", function() {
        $scope.tabs.forEach(function(tab) {
            tab.active = $scope.active(tab.route);
        });
    });
});


您接下来要做的就是将orderID.
这是一个演示

于 2015-06-19T10:52:54.093 回答