Skip to content

Instantly share code, notes, and snippets.

@strukturedkaos
Last active August 29, 2015 14:02
Show Gist options
  • Save strukturedkaos/8757f7728920ff79811e to your computer and use it in GitHub Desktop.
Save strukturedkaos/8757f7728920ff79811e to your computer and use it in GitHub Desktop.
Example of controllers.js for Angular task list
'use strict';
/* Controllers */
var taskListControllers = angular.module('taskListControllers', []);
taskListControllers.controller('TaskListCtrl', function TaskListCtrl($scope, $routeParams, $filter, $location, storage, Slug) {
'use strict';
var LIST_STORAGE_ID = 'lists';
storage.bind($scope, LIST_STORAGE_ID);
var defaultList = {
listId: Slug.slugify('Work tasks' + '-' + 0),
title: 'Work tasks',
tasks: [
{ title: 'Star Wars marathon', completed: false },
{ title: 'Basejump off cliff', completed: false },
{ title: 'Ride a bronco', completed: true },
{ title: 'Eat Beluga caviar', completed: false },
{ title: 'Climb Mt. Everest', completed: false },
{ title: 'Own a Bentley', completed: false },
{ title: 'Learn Tae-Kwon-Do', completed: false },
{ title: 'Create a successful startup', completed: false }
]};
...
var lists = $scope.lists = storage.get(LIST_STORAGE_ID) || [defaultList]
$scope.currentList = lists[0] || { tasks: [] };
var tasks = $scope.tasks = $scope.currentList.tasks;
...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment