Junerey Casuga
Lead Developer | Tagcash.com & Tagbond.com
...
Hello, {{ yourName }}!
var myApp = angular.module('myApp',[]);
myApp.controller('myController', function($scope) {
$scope.yourName = 'Joe';
$scope.attribute = 'awesome';
$scope.awesome = function() {
$scope.attribute = 'awesome';
};
$scope.cool = function() {
$scope.attribute = 'cool';
};
});
$scope.todos = [
{text: 'learn angular', done: true},
{text: 'build real-time app', done: false}
];
$scope.addtodo = function() {
$scope.todos.push({
text:$scope.todoText,
done:false
});
$scope.todoText = '';
};
$scope.remaining = function() {
var count = 0;
angular.forEach($scope.tods, function(todo) {
count += todo.done ? 0 : 1;
});
return count;
};
$scope.archive = function() {
var oldTodos = $scope.todos;
$scope.todos = [];
angular.forEach(oldTodos, function(todo) {
if (!todo.done) $scope.todos.push(todo);
});
};
ToDo
{{ remaining() }} of {{ todos.length }} remaining
archive
-
{{ todo.text }}
stores and syncs data in realtime
var myApp = angular.module('myApp', ['firebase']);
myApp.value('fbURL', 'https://dmmmsutodo.firebaseio.com/')
myApp.factory('ToDos', function($firebase, fbURL) {
return $firebase(new FIrebase(fbURL)).$asArray();
})
myApp.controller('myController', function($scope, $firebase, fbURL, Todos) {
...
})
$scope.todos = Todos;
$scope.addtodo = function() {
Todos.$add({text:$scope.todoText, done: false}).then(function() {
$scope.todoText = '';
});
};
$scope.remaining = function() {
var count = 0;
angular.forEach($scope.todos, function(todo) {
count += todo.done ? 0: 1;
});
return count;
};
$scope.markDone = function(taskId, done) {
var data = new Firebase(fbURL + taskId);
if(done) {
data.update({done: true});
} else {
data.update({done: false});
}
};
$scope.archive = function() {
angular.forEach($scope.todos, function(index) {
if(index.done) {
$scope.todos.$remove(index);
};
});
}