angular-ui-bootstrap插件API - Tabs

Tabs

案例

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href='../node_modules/bootstrap/dist/css/bootstrap.css'>
    <link rel="stylesheet" href='../node_modules/angular-ui-bootstrap/dist/ui-bootstrap-csp.css'>
    <script src="../node_modules/angular/angular.min.js"></script>
    <script src="../node_modules/angular-ui-bootstrap/dist/ui-bootstrap-tpls.js"></script>
    <style type="text/css">
        form.tab-form-demo .tab-pane {
            margin: 20px 20px;
        }
    </style>
    <script>
        angular.module('myApp',['ui.bootstrap'])
            .controller('TabsDemoCtrl', function ($scope, uibDateParser) {
                $scope.tabs = [
                    { title:'Dynamic Title 1', content:'Dynamic content 1' },
                    { title:'Dynamic Title 2', content:'Dynamic content 2', disabled: true }
                ];

                $scope.alertMe = function() {
                    setTimeout(function() {
                        $window.alert('You\'ve selected the alert tab!');
                    });
                };

                $scope.model = {
                    name: 'Tabs'
                };
            });
    </script>
</head>
<body>
<div ng-controller="TabsDemoCtrl">
    <p>Select a tab by setting active binding to true:</p>
    <p>
        <button type="button" class="btn btn-default btn-sm" ng-click="active = 1">Select second tab</button>
        <button type="button" class="btn btn-default btn-sm" ng-click="active = 2">Select third tab</button>
    </p>
    <p>
        <button type="button" class="btn btn-default btn-sm" ng-click="tabs[1].disabled = ! tabs[1].disabled">Enable / Disable third tab</button>
    </p>
    <hr />

    <uib-tabset active="active">
        <uib-tab index="0" heading="Static title">Static content</uib-tab>
        <uib-tab index="$index + 1" ng-repeat="tab in tabs" heading="{{tab.title}}" disable="tab.disabled">
            {{tab.content}}
        </uib-tab>
        <uib-tab index="3" select="alertMe()">
            <uib-tab-heading>
                <i class="glyphicon glyphicon-bell"></i> Alert!
            </uib-tab-heading>
            I've got an HTML heading, and a select callback. Pretty cool!
        </uib-tab>
    </uib-tabset>

    <hr />

    <uib-tabset active="activePill" vertical="true" type="pills">
        <uib-tab index="0" heading="Vertical 1">Vertical content 1</uib-tab>
        <uib-tab index="1" heading="Vertical 2">Vertical content 2</uib-tab>
    </uib-tabset>

    <hr />

    <uib-tabset active="activeJustified" justified="true">
        <uib-tab index="0" heading="Justified">Justified content</uib-tab>
        <uib-tab index="1" heading="SJ">Short Labeled Justified content</uib-tab>
        <uib-tab index="2" heading="Long Justified">Long Labeled Justified content</uib-tab>
    </uib-tabset>

    <hr />

    Tabbed pills with CSS classes
    <uib-tabset type="pills">
        <uib-tab heading="Default Size">Tab 1 content</uib-tab>
        <uib-tab heading="Small Button" classes="btn-sm">Tab 2 content</uib-tab>
    </uib-tabset>

    <hr />

    Tabs using nested forms:
    <form name="outerForm" class="tab-form-demo">
        <uib-tabset active="activeForm">
            <uib-tab index="0" heading="Form Tab">
                <ng-form name="nestedForm">
                    <div class="form-group">
                        <label>Name</label>
                        <input type="text" class="form-control" required ng-model="model.name"/>
                    </div>
                </ng-form>
            </uib-tab>
            <uib-tab index="1" heading="Tab One">
                Some Tab Content
            </uib-tab>
            <uib-tab index="2" heading="Tab Two">
                More Tab Content
            </uib-tab>
        </uib-tabset>
    </form>
    Model:
    <pre>{{ model | json }}</pre>
    Nested Form:
    <pre>{{ outerForm.nestedForm | json }}</pre>
</div>
</body>
</html>

效果

uib-tabset 配置

  • active  (Default: Index of first tab) - 选项卡索引。设置这个现有选项卡的标签索引。

    <button type="button" class="btn btn-default btn-sm" ng-click="uibTabDemo = 1">点击后切换到two</button>
        <uib-tabset active="uibTabDemo">
            <uib-tab index="0" heading="one">
                one
            </uib-tab>
            <uib-tab index="1" heading="two">
                two
            </uib-tab>
        </uib-tabset>

  • justified $ (Default: false) -标签填补容器的宽度受否一致。

    <uib-tabset active="activeJustified" justified="true">
            <uib-tab index="0" heading="Justified">Justified content</uib-tab>
            <uib-tab index="1" heading="SJ">Short Labeled Justified content</uib-tab>
            <uib-tab index="2" heading="Long Justified">Long Labeled Justified content</uib-tab>
            <uib-tab index="3" heading="Long ">Long Labeled content</uib-tab>
            <uib-tab index="4" heading="Justified">Justified content</uib-tab>
        </uib-tabset>

    <uib-tabset active="activeJustified" justified="false">
            <uib-tab index="0" heading="Justified">Justified content</uib-tab>
            <uib-tab index="1" heading="SJ">Short Labeled Justified content</uib-tab>
            <uib-tab index="2" heading="Long Justified">Long Labeled Justified content</uib-tab>
            <uib-tab index="3" heading="Long ">Long Labeled content</uib-tab>
            <uib-tab index="4" heading="Justified">Justified content</uib-tab>
        </uib-tabset>

    • template-url (Default: uib/template/tabs/tabset.html) - 一个URL代表组件使用的模板位置。
  • type (Defaults: tabs) - 导航类型。可能的值是“tabs”和“pills”。以下是pills类型

    <uib-tabset type="pills">
            <uib-tab heading="Default Size">Tab 1 content</uib-tab>
            <uib-tab heading="Small Button" classes="btn-sm">Tab 2 content</uib-tab>
        </uib-tabset>

  • vertical $ (Default: false) - 标签是否垂直堆叠显示(最好设置type为pills,因为ui-bootstrap并没有对对垂直显示做样式调整)。

    <uib-tabset active="activePill" vertical="true" type="pills">
            <uib-tab index="0" heading="Vertical 1">Vertical content 1</uib-tab>
            <uib-tab index="1" heading="Vertical 2">Vertical content 2</uib-tab>
        </uib-tabset>

uib-tab 配置

  • classes $ - 一个可选的字符串,内容为空格分隔的CSS类.这个类是作用到标签上的,而不是内容上的

    Tabbed pills with CSS classes
        <uib-tabset type="pills">
            <uib-tab heading="Default Size">Tab 1 content</uib-tab>
            <uib-tab heading="Small Button" classes="btn-sm">Tab 2 content</uib-tab>
        </uib-tabset>

  • deselect() $ - 当标签被激活时,一个可选的表达式

  • disable $  (Default: false) - 禁用选项卡

  • heading - 标题文本

    <uib-tabset>
            <uib-tab index="0" heading="one">
                one
            </uib-tab>
            <uib-tab index="1" heading="two">
                two
            </uib-tab>
        </uib-tabset>

  • index - 标签索引。必须是唯一的数字或字符串。

  • select() $ - 一个可选的表达式,当标签被激活时触发。

    $scope.tabs = [
                        { title:'Dynamic Title 1', content:'Dynamic content 1' },
                        { title:'Dynamic Title 2', content:'Dynamic content 2', disabled: true }
                    ];
    
                    $scope.alertMe = function() {
                        console.log('demo')
                    };

  • template-url (Default: uib/template/tabs/tab.html) - 一个URL的位置代表使用选项卡标题的模板。

Tabset heading

如果使用uib-tabset字符串标题无法满足需求,您也可以使用一个uib-tab-heading元素。也可以使用HTML。

<uib-tabset active="active">
        <uib-tab index="0" heading="Static title">Static content</uib-tab>
        <uib-tab index="1" select="alertMe()">
            <uib-tab-heading>
                <i class="glyphicon glyphicon-bell"></i> Alert!
            </uib-tab-heading>
            I've got an HTML heading, and a select callback. Pretty cool!
        </uib-tab>
    </uib-tabset>

 

已知的问题

要在标签中使用可点击元素(例如a标签),你必须改为使用div元素,而不是a元素,并设置相应的样式。

 

转载于:https://www.cnblogs.com/woleicom/p/5640165.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Element-UI 是一个基于 Vue.js 的 UI 组件库,如果要在 Angular 中使用 Element-UI,需要先安装 Vue.js,并且在 Angular 中集成 Vue.js。 具体步骤如下: 1. 安装 Vue.js 在 Angular 项目中安装 Vue.js,可以使用 npm 命令进行安装: ``` npm install vue --save ``` 2. 安装 Element-UIAngular 项目中安装 Element-UI,同样可以使用 npm 命令进行安装: ``` npm install element-ui --save ``` 3. 集成 Vue.js 在 Angular 中集成 Vue.js,可以使用 ngx-build-plus 插件。在 Angular 项目中安装 ngx-build-plus: ``` npm install ngx-build-plus --save-dev ``` 然后在 angular.json 文件中配置 ngx-build-plus: ``` "architect": { "build": { "builder": "ngx-build-plus:browser", "options": { "extraWebpackConfig": "./extra-webpack.config.js" }, "configurations": { "production": { "extraWebpackConfig": "./extra-webpack.config.js" } } } } ``` 在 extra-webpack.config.js 文件中配置 Vue.js 的 loader: ``` const VueLoaderPlugin = require('vue-loader/lib/plugin') module.exports = { module: { rules: [ { test: /\.vue$/, loader: 'vue-loader' }, { test: /\.js$/, loader: 'babel-loader' } ] }, plugins: [ new VueLoaderPlugin() ] } ``` 4. 在 Angular 中使用 Element-UIAngular 中使用 Element-UI,需要先在组件中引入 Vue.js 和 Element-UI: ``` import Vue from 'vue' import ElementUI from 'element-ui' Vue.use(ElementUI) ``` 然后在组件中使用 Element-UI 的组件: ``` <template> <el-button>Button</el-button> </template> <script> export default { name: 'MyComponent' } </script> ``` 这样就可以在 Angular 中使用 Element-UI 了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值