Created
March 1, 2015 17:04
-
-
Save chiquitinxx/a38ba0b54a405c11ece4 to your computer and use it in GitHub Desktop.
First approach angular controller
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
//Todo app controller written in groovy, from https://angularjs.org/ | |
def todoAngular = { $scope -> | |
$scope.todos = [ | |
[text:'learn angular', done: true], | |
[text:'build an angular app', done: false] | |
] | |
$scope.addTodo = { | |
$scope.todos << [text:$scope.todoText, done:false] | |
$scope.todoText = '' | |
} | |
$scope.remaining = { | |
$scope.todos.inject(0) { acc, todo -> | |
todo.done ? acc + 1 : acc | |
} | |
} | |
$scope.archive = { | |
$scope.todos = $scope.todos.findAll { !it.done } | |
} | |
} | |
/*And using it is js: | |
angular.module('todoApp', []) | |
.controller('TodoController', ['$scope', todoAngular]); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment