Last active
August 29, 2015 14:17
-
-
Save AllenFang/8688cec40fa822830661 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module("demoApp", []) | |
.directive("productContainer", function(){ | |
return{ | |
scope:{ | |
data: "=" | |
}, | |
templateUrl: "productsTemplate.html", | |
link: function(scope, el, attr){ | |
// splitSize 表示每列有幾個 product | |
scope.splitSize = parseInt(attr["splitSize"]); | |
}, | |
restrict: "AE" | |
}; | |
}).directive("productRow", function(){ | |
return{ | |
scope: {}, | |
templateUrl: "productRowTemplate.html", | |
link: function(scope, el, attr){ | |
scope.data = scope.$eval(attr.rowData); | |
}, | |
restrict: "E" | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-controller="ProductController" class="col-md-offset-4 col-md-4"> | |
<product-container data="products" split-size="3"></product-container> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class='col-md-4' ng-repeat='product in data'> | |
<div class='well'> | |
{{product.name}} | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-repeat='product in data' | |
ng-init="remainder= $index % splitSize; match= remainder == splitSize-1;"> | |
<div class='row' ng-if='match' ng-init="data= data.slice($index-(splitSize-1), $index+1)"> | |
<product-row row-data="{{data}}"></product-row> | |
</div> | |
<div class='row' ng-if='$last && !match' ng-init="data= data.slice($index-remainder, $index+1)"> | |
<product-row row-data="{{data}}"></product-row> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment