虽然我们可以用angular中的路由来做tab选项卡,但是那会让我们建立很多的页面来引入,或者建立 <script type="text/ng-template" id="news"></script>来装内容,
我认为都比较麻烦。所以我是使用angular中的json和angular中的ng-show来做选项卡的。

话不多说,上代码

html部分

<!--设置nav导航栏-->
<ul>
<!--nav中的导航栏内容,并给每个li设置点击事件,设置是否显示class样式-->
<li ng-repeat="v in wd" ng-click="wD($index)" class="{{wD1($index)?'wd':''}}">
{{v.font}}
</li>
</ul>
<!--设置tab选项卡的内容,并用ng-show来判断哪个tab内容显示-->
<ul ng-repeat="v in wd1" ng-show="wDBottom($index)">
<!--tab选项卡里的内容-->
<li ng-repeat="vv in v.Font">
{{vv.font}}
</li>
</ul>

js部分

<script type="text/javascript">
//angular模块
var app = angular.module("mk",[]);
//angular控制台
app.controller("ctrl",function($scope,$http){
$scope.contentwd = 0;
//建立一个json做nav导航
$scope.wd = [{"font":"1"},{"font":"2"},{"font":"3"},{"font":"4"},{"font":"5"}];
//建立一个json做tab选项卡中的内容
$scope.wd1 = [
{"Font":[
{"font":"tab1"},
{"font":"tab1"},
{"font":"tab1"}
]},
{"Font":[
{"font":"tab2"},
{"font":"tab2"},
{"font":"tab2"}
]},
{"Font":[
{"font":"tab3"},
{"font":"tab3"},
{"font":"tab3"}
]},
{"Font":[
{"font":"tab4"},
{"font":"tab4"},
{"font":"tab4"}
]},
{"Font":[
{"font":"tab5"},
{"font":"tab5"},
{"font":"tab5"}
]},
];
//导航栏中点击时获取下标来让哪个来显示
$scope.wD = function(index){
$scope.contentwd = index;
return $scope.contentwd;
}
//确定哪个导航栏的样式给哪个
$scope.wD1 = function(index){
return $scope.contentwd == index;
}
//获取下标来让哪个tab选项卡中的内容显示
$scope.wDBottom = function(index){
return $scope.contentwd == index;
}
})
</script>

css样式

<style type="text/css">
/*初始化页面*/
*{margin:0;padding:0;text-decoration: none;box-sizing: border-box;list-style: none;}
/*设置样式方便观看*/
ul:first-child{
width:500px;
height:50px;
margin:20px auto;
margin-bottom: 0;
}
ul:first-child>li{
width:100px;
height:50px;
border:1px solid #aaa;
text-align: center;
float: left;
line-height: 50px;
}
ul:first-child~ul{
width:500px;
height:350px;
margin:0px auto;
border: 1px solid #aaa;
}
/*给nav中添加的样式*/
.wd{
color:blue;
}
</style>

我认为这个是非常方便的;希望对大家有所帮助

用angular中的ng-repeat和ng-show来实现tab选项卡的更多相关文章

  1. Angular 中后台前端解决方案 - Ng Alain 介绍

    背景 之前项目使用过vue.js+iview,习惯了后端开发的我,总觉得使用不习惯,之前分析易企秀前端代码,接触到了angular js,完备的相关功能,类似后端开发的体验,让人耳目一新,全新的ang ...

  2. ui-router中的锚点问题(angular中的锚点问题)

    angular.module('anchorScrollExample', []) .controller('ScrollController', ['$scope', '$location', '$ ...

  3. angular中的MVVM模式

    在开始介绍angular原理之前,我们有必要先了解下mvvm模式在angular中运用.虽然在angular社区一直将angular统称为前端MVC框架,同时angular团队也称它为MVW(What ...

  4. angular源码分析:angular中的依赖注入式如何实现的

    一.准备 angular的源码一份,我这里使用的是v1.4.7.源码的获取,请参考我另一篇博文:angular源码分析:angular源代码的获取与编译环境安装 二.什么是依赖注入 据我所知,依赖注入 ...

  5. angular中$cacheFactory缓存的使用

    最近在学习使用angular,慢慢从jquery ui转型到用ng开发,发现了很多不同点,继续学习吧: 首先创建一个服务,以便在项目中的controller中引用,服务有几种存在形式,factory( ...

  6. 在 Angular 中实现搜索关键字高亮

    在 Angular 中,我们不应该试图直接修改 DOM 的内容,当需要更新 DOM 内容的时候,应该修改的其实是我们的数据模型,也就是 $scope 中的数据,Angular 会帮助我们将修改之后的数 ...

  7. Angular中 build的时候遇到的错误--There are multiple modules with names that only differ in casing

    今天早上遇到一个Angular的编译的时候的错误 具体信息: There are multiple modules with names that only differ in casing.This ...

  8. angular中的服务

    angular中的服务 angular中的服务相当于一个状态管理,可以将数据放在服务里面进行获取以及编辑. 服务的安装命令: ng g service count 安装好后,会在服务的ts文件中引入一 ...

  9. angular中使用代理

    使用代理 1.在跟目录创建proxy.config.json文件 { "/api": { "target": "http://localhost:30 ...

  10. Angular中的内置指令和自定义指令

    NG中的指令,到底是什么(what)? 为什么会有(why)?以及怎样使用(how)? What: 在NG中,指令扩展HTML功能,为 DOM 元素调用方法.定义行为绑定数据等. Why: 最大程度减 ...

随机推荐

  1. latex之转置符号

    $\mathbf{A}^\mathrm{T}$ $\mathbf{A}^\top$ $\mathbf{A}^\mathsf{T}$ $\mathbf{A}^\intercal$ 效果分别为:

  2. udhcpc

    /********************************************* * dhcpc * dhcpc是dhcp的客户端,在busybox中实现.今天正好了解一下. * Tony ...

  3. 使用Ultra Librarian转换芯片的Altium Designer封装格式

    第一步:找到对应芯片的CAD文件,以OPA350为例: http://www.ti.com/product/opa350   RE: 使用Ultra Librarian转换TI芯片的Altium De ...

  4. openstack热迁移和冷迁移

    转自: http://www.cnblogs.com/pycode/p/6494848.html 迁移类型: *非在线迁移 (有时也称之为‘迁移’).也就是在迁移到另外的计算节点时的这段时间虚拟机实例 ...

  5. 同一种类型的两个对象赋值,用反射。再也不用点属性了。。。。(适用于ef)

    /// <summary> /// 给对象赋值的方法(不赋地址)(同一个类型),含过滤 /// </summary> /// <typeparam name=" ...

  6. ThinkPHP中调用PHPExcel

    //引入PHPExcel vendor('PHPExcel.PHPExcel'); // Create new PHPExcel object $objPHPExcel = new PHPExcel( ...

  7. 【Windows】win10应用商店被删后恢复方法!

    以管理员身份运行PowerShell,输入以下命令后回车(可直接复制粘贴): Get-AppxPackage -AllUsers| Foreach {Add-AppxPackage -DisableD ...

  8. [jquery] jQuery 选择器>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. socket小实例

    服务端 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...

  10. mybatis由浅入深day02_7.3二级缓存

    7.3 二级缓存 7.3.1 原理 下图是多个sqlSession请求UserMapper的二级缓存图解. 首先开启mybatis的二级缓存. sqlSession1去查询用户id为1的用户信息,查询 ...