首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >angularjs ui-sref地址命名视图

angularjs ui-sref地址命名视图
EN

Stack Overflow用户
提问于 2015-06-19 16:36:15
回答 1查看 363关注 0票数 0

我想做这样的事情:

代码语言:javascript
复制
.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,在其中我可以选择要寻址的选项卡;如下所示:

代码语言:javascript
复制
ui-sref="tabs.order({orderId:order.ID}, <orders-tab or orders-all-tab?>)"

这有可能吗?谢谢

EN

回答 1

Stack Overflow用户

发布于 2015-06-19 18:52:54

好吧,我不认为有任何方法可以在ui-sref中指定视图,但这里有一个起点,我希望它能帮助你。

第一,路线:

代码语言:javascript
复制
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

代码语言:javascript
复制
<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>

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

代码语言:javascript
复制
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

这是一个demo

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30933620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档