Skip to content

Instantly share code, notes, and snippets.

@scionwest
Created November 6, 2016 16:53
Show Gist options
  • Save scionwest/9e75f5a518fa409367dd2c3d65b2187f to your computer and use it in GitHub Desktop.
Save scionwest/9e75f5a518fa409367dd2c3d65b2187f to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html ng-app="store">
<head>
<link rel="stylesheet" type="text/css" href="node_modules/bootstrap/dist/css/bootstrap.min.css" />
<script type="text/javascript" src="node_modules/angular/angular.min.js"></script>
<script type="text/javascript" src="content/js/app.js"></script>
</head>
<body ng-controller="StoreController as store">
<div ng-repeat="product in store.products">
<h1>{{product.name}}</h1>
<h2>{{product.price | currency}}</h2>
<p>{{product.description}}</p>
<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)">Description</a>
</li>
<li ng-class="{ active: panel.isSelected(2)}">
<a href ng-click="panel.selectTab(2)">Specifications</a>
</li>
<li ng-class="{ active: panel.isSelected(3)}">
<a href ng-click="panel.selectTab(3)">Reviews</a>
</li>
</ul>
<div class="panel" ng-show="panel.isSelected(1)">
<h4>Description</h4>
<p>{{product.description}}</p>
</div>
<div class="panel" ng-show="panel.isSelected(2)">
<h4>Specifications</h4>
<blockquote>None</blockquote>
</div>
<div class="panel" ng-show="panel.isSelected(3)">
<h4>Reviews</h4>
<blockquote>None.</blockquote>
</div>
</section>
</div>
</body>
</html>
app.controller('PanelController', function() {
this.tab = 1;
this.products = [
{
name: 'Apples',
price: 64.99,
description: 'Red Apples'
},
{
name: 'Oranges',
price: 23.99,
description: 'Fat oranges'
}];
this.selectTab = function(setTab) {
this.tab = setTab;
};
this.isSelected = function(checkTab) {
return this.tab === checkTab;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment