Here is the little app in which you can add items, edit them and delete - all described in controller, based on angular 2 way data-bind.
http://cssdeck.com/labs/schedule-of-the-red-hood
Everytime the element is added, in the calednar-bar programmatically should be inserted an element, described in directive's template:
template: '<div ng-repeat="event in events" class="event">' +
'<h3 ng-model="event.Name">{{event.Name}}</h3>' +
'<span ng-model="event.StartTime; event.EndTime" class="time">{{event.StartTime}}-{{event.EndTime}}</span>' +
'</div>'
Though I can't get it how to link the scope from controller, bind the element insertion from the controller:
$scope.addEvent = function(event, attrs) {
$scope.events.push(event);
$scope.event = {};
var eventGrid = angular.element(document.createElement('eventGrid')),
el = $compile(eventGrid)($scope);
angular.element(document.body).append(eventGrid);
$scope.insertHere = el;
}
- as I understand now, my code creates an element in the DOM, but doesn't use template from directive... How can I do it? Is the chosen structure of code appropriate to this goal?