Last active
June 5, 2020 05:12
-
-
Save rktjmp/4653222 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
// Make our app module, its easier to do this in raw javascript | |
// and then put the rest of our app content (controllers etc) | |
// in their own coffeescript files. | |
// | |
// Your ng-app should include this module name, eg: <html ng-app="TodoApp"> | |
angular.module('TodoApp', []); |
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
# Original source at: http://angularjs.org/#todo-js | |
angular.module('TodoApp').controller 'TodoCtrl', ($scope) -> | |
$scope.todos = [ | |
{text: 'learn angular', done: true}, | |
{text: 'build an angular app', done: false} | |
] | |
$scope.addTodo = -> | |
$scope.todos.push({text: $scope.todoText, done: false}) | |
$scope.todoText = '' | |
$scope.remaining = -> | |
count = 0 | |
for todo in $scope.todos | |
count += todo.done ? 0: 1 | |
count | |
$scope.archive = -> | |
oldTodos = $scope.todos | |
$scope.todos = [] | |
for todo in oldTodos | |
$scope.todos.push(todo) unless todo.done |
It's better to write like below. Otherwise, it doesn't work if you use minify to build the script.
['$scope', ($scope) ->
]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not quite sure, but it seems the controller definition in todo.coffee is re-initizalizing the whole app. I was struggling with this as I wanted to add a configuration like this
and it never got called.