Skip to content

Instantly share code, notes, and snippets.

@SoldierCoder
Last active August 29, 2015 14:05
Show Gist options
  • Save SoldierCoder/f8a9de0227f6ba530d82 to your computer and use it in GitHub Desktop.
Save SoldierCoder/f8a9de0227f6ba530d82 to your computer and use it in GitHub Desktop.
Brute force -- embedded panel names
app.controller('PanelController', function() {
this.items = badges;
this.tab = 1;
this.selectTab = function(setTab) {
this.tab = setTab;
};
this.isSelected = function(checkTab) {
return this.tab === checkTab;
};
});
<section ng-controller="PanelController as panel">
<ul class="nav nav-pills">
<li ng-class="{ active: panel.isSelected(1) }">
<a href="" ng-click="panel.selectTab(1)">Angular</a>
</li>
<li ng-class="{ active: panel.isSelected(2) }">
<a href="" ng-click="panel.selectTab(2)">Rails 3.2-4.0</a>
</li>
<li ng-class="{ active: panel.isSelected(3) }">
<a href="" ng-click="panel.selectTab(3)">RSpec for Rails</a>
</li>
<li ng-class="{ active: panel.isSelected(4) }">
<a href="" ng-click="panel.selectTab(4)">Testing for Rails</a>
</li>
</ul>
<div class="panel" ng-show="panel.isSelected(1)">
<h4>Angular</h4>
</div>
<div class="panel" ng-show="panel.isSelected(2)">
<h4>Ruby on Rails</h4>
</div>
<div class="panel" ng-show="panel.isSelected(3)">
<h4>RSpec</h4>
</div>
<div class="panel" ng-show="panel.isSelected(4)">
<h4>Testing</h4>
</div>
</section>
@SoldierCoder
Copy link
Author

Ok the code above lets me have tabbed panels in twitter bootstrap. But it's yucky in that it is hard coded. I'd like to use ng-repeat, but how do I pass along which panel.isSelected, and allow user to panel.selectTab???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment