Angular ui 选项卡,每个选项卡都有单独的控制器

编程入门 行业动态 更新时间:2024-10-28 19:20:08
本文介绍了Angular ui 选项卡,每个选项卡都有单独的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想制作一个引导标签集,每个标签都有自己的控制器.谁能指点我该往哪个方向走.

I would like to make a bootstrap tabset with each tab having it's own controller. Can anyone point me in which direction I should go.

目前我制作了几个不同的控制器,我想在标签集中使用它们,而不是让它们显示为不同的路线.

Currently I have made several difference controllers, which I would like to be used in a tabset instead of having them displayed as a different route.

我知道我可以通过让不同控制器模板中的标签集将给定的控制器标签显示为活动来伪造它,但我希望能够有一个带有多个子控制器的主 TabController(对于每个标签)

I know I could fake it by having the tabset in the difference controller templates displaying the given controllers tab as active, but I would like to be able to have a main TabController with several child controllers (for each tab)

推荐答案

如果您使用的是 angular ui 路由器,您可以使用嵌套状态来执行此操作.

If you are using angular ui router you can use nested states to do this.

使用包含选项卡和嵌套 ui-view 的视图创建抽象状态为每个选项卡创建一个子状态,每个子状态都继承自抽象状态

每个子状态可以设置嵌套的ui-view的内容,并定义一个控制器 Create an abstract state with a view that contains the tabs and a nested ui-view Create a child state for each of your tabs, each inheriting from the abstract state

Each child state can set the content of the nested ui-view, and define a controller

 $stateProvider.state( 'tabs', {
    abstract: true,
        url: 'tabs',
        views: {
          "tabs": {
            controller: 'TabsCtrl',
            templateUrl: 'tabs.html'
          }
        }
      })
      .state('tabs.tab1', {
          url: '',  //make this the default tab
          views: {
          "tabContent": {
            controller: 'Tab1Ctrl',
            templateUrl: 'tab1.html'
          }
        }
      })
      .state('tabs.tab2', {
          url: '/tab2',
          views: {
          "tabContent": {
            controller: 'Tab2Ctrl',
            templateUrl: 'tab2.html'
          }
        }
      });

这篇关于Angular ui 选项卡,每个选项卡都有单独的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-21 06:21:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/998246.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选项卡   都有   控制器   Angular   ui

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!