Created
May 21, 2016 19:41
-
-
Save sgen/74c96f2b87e7d892f79bbb9cbb744bb4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
angular.module('ToDoApp') | |
.controller('ToDoController', ['ToDoService', function(ToDoService) { | |
var ToDoController = this; | |
ToDoController.selected = null; | |
ToDoController.todos = []; | |
ToDoController.foo = 'Testing'; | |
ToDoController.selectToDo = selectToDo; | |
ToDoService().get() | |
.then(function(todos) { | |
ToDoController.todos = ToDoController.todos.concat(todos); | |
ToDoController.selectToDo(todos[0]); | |
}); | |
function selectToDo(todo) { | |
if (todo) self.selected = todo; | |
} | |
}]); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
angular.module('ToDoApp', ['ngMaterial']); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
angular.module('ToDoApp') | |
.service('ToDo', function() { | |
return function(title, description) { | |
title = title || ''; | |
description = description || ''; | |
var ToDo = { | |
title: title, | |
description: description | |
}; | |
return ToDo; | |
} | |
}); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
angular.module('ToDoApp') | |
.service('ToDoService', ['$q', 'ToDo', function($q, ToDo) { | |
var todos = [ | |
ToDo('ToDo 1', 'Write ToDo in Angular'), | |
ToDo('ToDo 3', '???'), | |
ToDo('ToDo 4', 'profit') | |
]; | |
return function() { | |
var ToDoService = {}; | |
ToDoService.get = get; | |
function get() { | |
return $q.when(todos); | |
} | |
return ToDoService; | |
}; | |
}]); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment