AngularJS ngRepeat and orderBy.

by Sajeetharan Sinnathurai

HTML

<div ng-controller="DemoCtrl">
<div ng-repeat="item in items" style="display:inline-block;width:120px;">
<div>{{item.listTitle}}</div>
    <div ng-repeat="inner in item.items">{{inner}}</div>
    <div id="compose_{{$index}}"></div>
<a href="javascript:void(0)" data-ng-click="addNewCardToList($index);">Add a card...</a>
</div>
<br />
<a href="javascript:void(0)" ng-click="showInput = ! showInput">Add a list...</a>
<div ng-show="showInput">
<input type="text" placeholder="Add a list..." name="title" ng-model="c.newList">
<a href="javascript:void(0)" data-ng-click="addNewList()">Save</a>
</div>
</div>

JavaScript

angular.module('app', []).controller('DemoCtrl',function($scope,$compile,$window){
    $scope.items = [];
    $scope.idx = '';
    $scope.c = {};

$scope.addNewList = function () {
if(typeof $scope.c.newList === 'undefined'){
 alert('list title blank');
 return;
}
$scope.items.push({listTitle: $scope.c.newList});
$scope.c.newList = '';
};

$scope.addNewCardToList = function(idx) {
$scope.idx = idx;
var elm = '<div class="list-card"><textarea style="overflow: hidden; word-wrap: break-word; resize: none; height: 56px;" ng-model="c.title"></textarea><input type="button" value="Add" ng-click="saveNewCardToList(idx)"><a href="javascript:void(0)" ng-click="closeCard(idx)">X</a><a href="javascript:void(0)"></a></div>';
var temp = $compile(elm)($scope);
if($window.document.getElementsByClassName("list-card").length === 0)
 angular.element(document.querySelector('#compose_'+idx)).append(temp);
};
});