在ngStrap 2.1.0+中的选项卡中使用模板吗?

提摩太

在ngStrap的2.1.0版本中,它们重写了Tabs指令。他们在选项卡上的文档现在没有任何在选项卡中使用模板的示例。我在使用2.0.5的页面上使用了Tabs,但是由于其他原因,不得不进行升级。我想确保我在github上打开问题之前不会丢失任何内容。ngStrap的站点仍然将模板作为选项列出,即使他们删除了所有示例。

制作我的标签的代码是:

$scope.tabs = [
{
    title: "Tab 1",
    template: "tab1.html"
},
{
    title: "Tab 2",
    template: "tab2.html"
}];

我尝试了几种不同类型的显示选项卡。它们在下面,可以在此plnkr中进行测试:http ://plnkr.co/edit/zEQ8mP6IkvCVPlYqxR59?p=preview

尝试1:

<div bs-tabs>
    <div ng-repeat="tab in tabs" title="{{ tab.title }}"  template="{{tab.template}}" bs-pane></div>
</div>

尝试2:

<div bs-tabs>
    <div ng-repeat="tab in tabs" title="{{ tab.title }}"  template="tab.template" bs-pane></div>
</div>

尝试3:

<div bs-tabs>
    <div ng-repeat="tab in tabs" title="{{ tab.title }}"  ng-bind="tab.template" bs-pane></div>
</div>

尝试4:

<div bs-tabs>
    <div ng-repeat="tab in tabs" title="{{ tab.title }}"  template="tab.template" bs-pane></div>
</div>

任何帮助表示赞赏!谢谢!

提摩太

我最终创建了一个解决方法。我正在发布,因此希望可以帮助其他人。

我最终创建了一个名为myTabs的新指令,因此在index.html中,我只是将

<my-tabs tabs="tabs"></my-tabs>

还有一个“ static-include”指令,基本上是ng-include,但不会创建新作用域。

希望这可以帮助某人!

这是plnkr:http ://plnkr.co/edit/MVbAN0uif9REjPjUusnr?p=preview

app.js具有:

$scope.tabs = [
{
  title: "Tab 1",
  show: true, //this is so this tab shows by default
  templateUrl: "tab1.html"
},
{
  title: "Tab 2",
  templateUrl: "tab2.html"
}];

myTabs.html-这是选项卡的模板。

<ul class="myTabs">
    <li ng-repeat="tab in tabs" ng-class="{active: tab.show}" ng-click="setActiveTab(tab.title)">{{tab.title}}</li> 
</ul> <br/><br/>
<div ng-repeat="tab in tabs" ng-show="tab.show"> 
    <div static-include="{{tab.templateUrl}}"></div>
</div>

myTabs.js

(function (ng) {
    ng.module('plunker')
        .directive('myTabs', [function() {
                return {
                    restrict: 'AE',
                    scope: false,
                    templateUrl: 'myTabs.html',
                    link: function(scope, element, attrs) {
                        scope.tabs = scope.$eval(attrs.tabs);

                        scope.setActiveTab = function(title) {
                            for (var i = 0; i < scope.tabs.length; i++) {
                                scope.tabs[i].show = false; // hide all the other tabs 

                                if (scope.tabs[i].title === title) {
                                    scope.tabs[i].show = true; // show the new tab 
                                }
                            }
                        }
                    }
                };
            }
        ])

    .directive('staticInclude', function ($http, $templateCache, $compile) {
        return function (scope, element, attrs) {
            var templatePath = attrs.staticInclude;
            $http.get(templatePath, { cache: $templateCache }).success(function (response) {
                var contents = element.html(response).contents();
                $compile(contents)(scope);
            });
        };
    });
}(angular));

style.css

.myTabs {
  list-style: none;
  position: relative;
  text-align: left;
  float: left;
  border-bottom: 1px solid lightgrey;
  width: 100%;
  padding-left: 0; }
  .myTabs li {
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    padding: 15px 8px 15px 50px;
    font-weight: 0;
    float: left;
    display: block;
    padding: 10px;
    background-color: white;
    border-bottom: 1px solid lightgrey;
    margin: 0;
    margin-bottom: -1px; }
    .myTabs li:hover {
      background-color: lightgrey;
      cursor: pointer; }
  .myTabs li.active {
    display: block;
    padding: 10px;
    background-color: white;
    border-bottom: 0px solid lightgrey;
    border-top: 1px solid lightgrey;
    border-left: 1px solid lightgrey;
    border-right: 1px solid lightgrey; }
    .dsTabs li.active:hover {
      background-color: white;
      cursor: pointer; }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在ngStrap 2.1.0+中的选项卡中使用模板吗?

来自分类Dev

我如何在ST2中使用Emmet在Handlebars模板(emberjs)中扩展HTML选项卡?

来自分类Dev

我如何在ST2中使用Emmet在Handlebars模板(emberjs)中扩展HTML选项卡?

来自分类Dev

使用Scala收集方法可帮助将[0,0,0,1,1,1,1,0,0,1,1]的列表转换为[3,4,2,2]

来自分类Dev

为什么1/2 == 0使用double?

来自分类Dev

在R中将(0,1,0,0,1,1,1)转换为(0,0,0,1,0,1,2)

来自分类Dev

在iTerm2中使用特定目录打开多个选项卡

来自分类Dev

索引 = 2 不在 [0, 1)

来自分类Dev

NgStrap的Aside不能正确显示

来自分类Dev

如何理解打字稿中类型定义中的[[0,1,2,... 0 []]`?

来自分类Dev

在Angular 2中使用Angular 1库吗?

来自分类Dev

在具有默认键值(0,1,2,...)的数组中使用extract()时会发生什么

来自分类Dev

在R ggplot2中,包括stat_ecdf()端点(0,0)和(1,1)

来自分类Dev

有什么更好的写方式[[-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1), (1,0),(1,1)]在Haskell吗?

来自分类Dev

diff file1 和 file2 的输出中的 `0a1`

来自分类Dev

为什么Unix权限系统使用1 2 3 4 ...值而不是1或0?

来自分类Dev

ActionBar选项卡:从片段1到片段2的onclick按钮

来自分类Dev

为什么2 **(1 << 31)== 0?

来自分类Dev

标签长度2应该为1或0

来自分类Dev

在2个磁盘上突袭0 + 1

来自分类Dev

Android - 获取数字的索引 #0 、 #1 、 #2

来自分类Dev

该代码的含义([1、2、3] || 0)[0]

来自分类Dev

该代码的含义([1、2、3] || 0)[0]

来自分类Dev

Excel:从表A的Col2自动填充表B的Col2单元格(如果选项卡1的Col 1与选项卡2的Col 1匹配)

来自分类Dev

在Ionic 2中将数据从子选项卡传递到父选项卡

来自分类Dev

从3rdfragment选项卡过渡到2nd / 1stfragment选项卡,中断了应用程序

来自分类Dev

引导程序选项卡中的标题<h1>?

来自分类Dev

值更改(避免0 1到1 2)

来自分类Dev

T(0) = 1, T(1) = 0, T(n ) = 2* T(n-2) 的递归关系

Related 相关文章

  1. 1

    在ngStrap 2.1.0+中的选项卡中使用模板吗?

  2. 2

    我如何在ST2中使用Emmet在Handlebars模板(emberjs)中扩展HTML选项卡?

  3. 3

    我如何在ST2中使用Emmet在Handlebars模板(emberjs)中扩展HTML选项卡?

  4. 4

    使用Scala收集方法可帮助将[0,0,0,1,1,1,1,0,0,1,1]的列表转换为[3,4,2,2]

  5. 5

    为什么1/2 == 0使用double?

  6. 6

    在R中将(0,1,0,0,1,1,1)转换为(0,0,0,1,0,1,2)

  7. 7

    在iTerm2中使用特定目录打开多个选项卡

  8. 8

    索引 = 2 不在 [0, 1)

  9. 9

    NgStrap的Aside不能正确显示

  10. 10

    如何理解打字稿中类型定义中的[[0,1,2,... 0 []]`?

  11. 11

    在Angular 2中使用Angular 1库吗?

  12. 12

    在具有默认键值(0,1,2,...)的数组中使用extract()时会发生什么

  13. 13

    在R ggplot2中,包括stat_ecdf()端点(0,0)和(1,1)

  14. 14

    有什么更好的写方式[[-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1), (1,0),(1,1)]在Haskell吗?

  15. 15

    diff file1 和 file2 的输出中的 `0a1`

  16. 16

    为什么Unix权限系统使用1 2 3 4 ...值而不是1或0?

  17. 17

    ActionBar选项卡:从片段1到片段2的onclick按钮

  18. 18

    为什么2 **(1 << 31)== 0?

  19. 19

    标签长度2应该为1或0

  20. 20

    在2个磁盘上突袭0 + 1

  21. 21

    Android - 获取数字的索引 #0 、 #1 、 #2

  22. 22

    该代码的含义([1、2、3] || 0)[0]

  23. 23

    该代码的含义([1、2、3] || 0)[0]

  24. 24

    Excel:从表A的Col2自动填充表B的Col2单元格(如果选项卡1的Col 1与选项卡2的Col 1匹配)

  25. 25

    在Ionic 2中将数据从子选项卡传递到父选项卡

  26. 26

    从3rdfragment选项卡过渡到2nd / 1stfragment选项卡,中断了应用程序

  27. 27

    引导程序选项卡中的标题<h1>?

  28. 28

    值更改(避免0 1到1 2)

  29. 29

    T(0) = 1, T(1) = 0, T(n ) = 2* T(n-2) 的递归关系

热门标签

归档