Skip to content

Instantly share code, notes, and snippets.

@got5
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save got5/c6142a7670e7d3ec602c to your computer and use it in GitHub Desktop.
Save got5/c6142a7670e7d3ec602c to your computer and use it in GitHub Desktop.
Slide 113 TP8
(function(){
"use strict";
angular.module('app').directive('productSummary', ['ProductUtils', function (ProductUtils) {
return {
restrict: 'E',
templateUrl: 'templates/partials/productSummary.html',
scope:{
product:'='
},
link: function (scope, element, attrs) {
scope.getRatingClass = ProductUtils.getRatingCss;
},
controller: ['$scope',
'UserService',
function ($scope,UserService) {
$scope.addToCart = function (pItem) {
UserService.addToCart(pItem, 1);
};
}]
}
}]);
})();
<article class="k-product hproduct">
<div class="photo-data">
<p>
<a href="#">
<img class="photo" ng-src="img/catalog/{{product.id}}.jpg" />
</a>
</p>
</div>
<p class="extra new" ng-if="product.isNew">new</p>
<h3 class="fn name">
<a ng-href="#/book/{{product.id}}" title="See Product sheet">{{product.name}}</a>
</h3>
<p ng-class="getRatingClass(product)">
<span ng-show="product.comments">
<a href="#comments">{{product.comments.length}} comment(s)</a>
</span>
<span ng-hide="product.comments">
No comment
</span>
</p>
<div class="price-data">
<p class="all-prices">
<strong class="price new">{{product.price | currency}}</strong>
</p>
</div>
<div class="buyZone">
<p class="buy">
<a ng-click="addToCart(product)">Add to basket</a>
</p>
</div>
</article>
<!-- hproduct/ -->
<product-summary product="product" ng-repeat="product in products"/>
<!-- /hproducts -->
<script src="js/directives/productSummary.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment