AngularJS Service Dependencies

by Edward Tanguay

HTML

<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<div ng-app="app">
    <div ng-controller="CalculatorController">
        <span ng-bind-html="getHtml(message)"></span>
    </div>
</div>

CSS

body {
    font-family:sans-serif;
    background-color: #f5f5f5;
}
div {
    margin:20px 5px;
}

JavaScript

angular.module('app', [])
.controller('CalculatorController', function($scope, $log, $sce) {
    
	$scope.message = '';
    
    $scope.showAll = function(events) {
        for(var i = 0; i < events.length; i++) {
            $scope.message += '('+ events[i].id + ') ';
        }        
        $scope.message += '<hr/>';
    };
    
    $scope.deleteItem = function(events,id) {
        events = events.filter(function( obj ) {
            return obj.id != id;
        });    
        return events;
    };
    
    $scope.getHtml = function (html) {
        return $sce.trustAsHtml(html);
    };
    
    var events = [
            {
                id: 1,
                title: 'All Day Event',
                start: '2015-02-02'
            },
            {
                id: 2,
                title: 'Long Event',
                start: '2015-02-07',
                end: '2015-02-10'
            },
            {
                id: 3,
                title: 'Repeating Event',
                start: '2015-02-09T16:00:00',
                color: 'red',
                borderColor: 'black'
            },
            {
                id: 4,
                title: 'Repeating Event',
                start: '2015-02-16T16:00:00'
            }
        ];
    
	$scope.showAll(events);
	events = $scope.deleteItem(events,2);
	$scope.showAll(events);
	events = $scope.deleteItem(events,4);
	$scope.showAll(events);
});