angular.module('components', []).directive('category', function () {
return {
restrict: 'E',
scope: {},
templateUrl: '/Scripts/app/partials/CategoryComponent.html',
controller: function ($scope, $http, $attrs) {
$http({
url: "api/FeaturedProducts/" + $attrs.catName,
method: "get"
}).success(function (data, status, headers, config) {
$scope.Cat = data;
}).error(function (data, status, headers, config) {
$scope.data = data;
$scope.status = status;
});
}
}
});
CategoryComponent.html
<a href="#/Categories/">
<h4></h4>
</a>
<div ng-switch on="status">
<div ng-switch-when="500" class="alert alert-error">
</div>
<div ng-switch-default>
<ul class="unstyled columns">
<li class="pin" ng-repeat="p in Cat.Products">
<a href="#/reviews/">
<h5></h5>
<img src="">
</a>
</li>
</ul>
</div>
</div>
usage
<ul class="unstyled">
<li>
<category cat-name="Ultrabooks"></category>
</li>
<li>
<category cat-name="Tablets"></category>
</li>
<li>
<category cat-name="Laptops"></category>
</li>
<li>
<category cat-name="Digital SLR Cameras"></category>
</li>
</ul>