<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#tabWrap button.active{
background-color: yellow;
}
#tabWrap div{
width: 200px;
height: 200px;
background-color: #ccc;
display: none;
}
#tabWrap div.active{
display: block;
}
</style>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<div id="tabWrap">
<button ng-repeat="item in tabs" ng-class="{true:'active',false:''}[$index==activeIndex]" ng-click="changeIndex($index)">
{{item.btn}}
</button>
<div ng-repeat="item in tabs" ng-class="{true:'active',false:''}[$index==activeIndex]">
{{item.content}}
</div>
</div>
</body>
<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript">
var myApp = angular.module("myApp",[])
myApp.controller('myCtrl', ['$scope', function($scope){
// model->服务器返回的数据
$scope.tabs = [
{btn:"按钮1", content: "买菜", id:1},
{btn:"按钮2", content: "学习",id:2},
{btn:"按钮3", content: "打游戏",id:3}
];
// 激活的下标
$scope.activeIndex = 0;
$scope.changeIndex = function (index){
// console.log(index)
$scope.activeIndex = index;
}
}])
</script>
</html>
网友评论