javascript - make jquery tab using ngRoute angularjs doesn't work -
i try add item in tab 1, navigate next tab, when come back, things got reset.
http://plnkr.co/edit/etxaz2esi9ftcousrdcp?p=preview
what best approach build jquery tab using angular? ngshow , hide not friendly makes view complicated , messy.
i suggest using bootstrap components written angularui team. can find great set of twitter bootstrap components including tabs control.
example:
<div ng-controller="tabsdemoctrl"> <p>select tab setting active binding true:</p> <p> <button class="btn btn-default btn-sm" ng-click="tabs[0].active = true">select second tab</button> <button class="btn btn-default btn-sm" ng-click="tabs[1].active = true">select third tab</button> </p> <p> <button class="btn btn-default btn-sm" ng-click="tabs[1].disabled = ! tabs[1].disabled">enable / disable third tab</button> </p> <hr /> <tabset> <tab heading="static title">static content</tab> <tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active" disabled="tab.disabled"> {{tab.content}} </tab> <tab select="alertme()"> <tab-heading> <i class="glyphicon glyphicon-bell"></i> alert! </tab-heading> i've got html heading, , select callback. pretty cool! </tab> </tabset> <hr /> <tabset vertical="true" type="navtype"> <tab heading="vertical 1">vertical content 1</tab> <tab heading="vertical 2">vertical content 2</tab> </tabset> <hr /> <tabset justified="true"> <tab heading="justified">justified content</tab> <tab heading="sj">short labeled justified content</tab> <tab heading="long justified">long labeled justified content</tab> </tabset> </div>
js:
var tabsdemoctrl = function ($scope) { $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() { alert("you've selected alert tab!"); }); }; $scope.navtype = 'pills'; };
live example: http://plnkr.co/edit/exdymwfk0fkgk0idw47q?p=preview
Comments
Post a Comment