i have two arrays one for alphabets and second for tags.. So i want to show only same alphabets items in that particular alphabet category example -- apple has to come in A category and zoo has to come in Z category...
fiddle link http://jsfiddle.net/4dGxn/149/
html
<div class="form-group" ng-controller="mainCtrl">
<div ng-repeat="alp in alpha">
<h2>{{alp}}</h2>
<ul>
<li ng-repeat="tag in tags">{{tag}}</li>
</ul>
</div>
</div>
angular
var app = angular.module("app", []);
app.controller("mainCtrl", ['$scope', function($scope){
$scope.alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p","q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
$scope.tags = ["apple", "dog", "cat", "dad", "baby", "zoo", "love", "hate", "rat", "room", "home", "age", "bad"];
}]);
You can use str.startsWith
to check if element starts with a particular character
So in your example:
<div class="form-group" ng-controller="mainCtrl">
<div ng-repeat="alp in alpha">
<h2>{{alp}}</h2>
<ul>
<li ng-repeat="tag in tags" ng-show="{{tag.startsWith(alp)}}">{{tag}}</li>
</ul>
</div>
</div>
Here is the wirking Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With