Skip to content

Instantly share code, notes, and snippets.

@chiquitinxx
Created March 1, 2015 17:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiquitinxx/a38ba0b54a405c11ece4 to your computer and use it in GitHub Desktop.
Save chiquitinxx/a38ba0b54a405c11ece4 to your computer and use it in GitHub Desktop.
First approach angular controller
//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