angular怎么实现tab切换

 我来答
百度网友10a24bf
2017-05-20 · TA获得超过1.3万个赞
知道大有可为答主
回答量:1.3万
采纳率:95%
帮助的人:2889万
展开全部
angularjs中tab标签切换的实现方法如下:
1、定义div容器:
<div ng-app="TabsApp"> <div id="tabs" ng-controller="TabsCtrl"> <ul> <li ng-repeat="tab in tabs" ng-class="{active:isActiveTab(tab.url)}" ng-click="onClickTab(tab)">{{tab.title}}</li> </ul> <div id="mainView"> <div ng-include="currentTab"></div> </div> </div> <script type="text/ng-template" id="one.tpl.html"> <div id="viewOne"> <h1>View One</h1> <p>Praesent id metus massa, ut blandit odio. Proin quis tortor orci. Etiam at risus et justo dignissim congue. Donec congue lacinia dui, a porttitor lectus condimentum laoreet. Nunc.</p> </div> </script> <script type="text/ng-template" id="two.tpl.html"> <div id="viewTwo"> <h1>View Two</h1> <p>Curabitur vulputate, ligula lacinia scelerisque tempor, lacus lacus ornare ante, ac egestas est urna sit amet arcu. Class aptent taciti sociosqu.</p> </div> </script> <script type="text/ng-template" id="three.tpl.html"> <div id="viewThree"> <h1>View Three</h1> <p>In pellentesque faucibus vestibulum. Nulla at nulla justo, eget luctus tortor. Nulla facilisi. Duis aliquet egestas purus in blandit. Curabitur vulputate, ligula lacinia scelerisque tempor, lacus lacus ornare ante, ac egestas est urna sit amet arcu. Class aptent taciti sociosqu.</p> </div> </script></div>
2、angularjs实现方法:
angular.module('TabsApp', []).controller('TabsCtrl', ['$scope', function ($scope) { $scope.tabs = [{ title: 'One', url: 'one.tpl.html' }, { title: 'Two', url: 'two.tpl.html' }, { title: 'Three',
url: 'three.tpl.html' }]; $scope.currentTab = 'one.tpl.html'; $scope.onClickTab = function (tab) { $scope.currentTab = tab.url; } $scope.isActiveTab = function(tabUrl) { return tabUrl == $scope.currentTab; }}]);
3、实现效果
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式