[Firebase] 2. Firebase Event Handling
/**
* Created by Answer1215 on 11/9/2014.
*/ var app = angular.module('app', ['firebase']); app.constant('FIREBASE_URI', 'https://zhentiw-angular-fire.firebaseio.com/'); app.controller('MainCtrl', ['$scope', 'ItemsService', function ($scope, ItemsService) {
$scope.newItem = { name: '', description: '', count: 0 };
$scope.currentItem = null;
$scope.isUpdated = false; $scope.items = ItemsService.getItems(); $scope.items.$on('change', function(){
if(!$scope.isUpdated){return;}
console.log("ITEMS CHANGE");
}); $scope.items.$on('loaded', function(){
console.log("ITEMS LOADED");
}); //Deattach the change event from the items
//$scope.items.$off('change'); $scope.addItem = function () {
ItemsService.addItem(angular.copy($scope.newItem));
$scope.newItem = { name: '', description: '', count: 0 };
}; $scope.updateItem = function (id){
$scope.isUpdated = true;
ItemsService.updateItem(id);
}; $scope.removeItem = function (id) {
ItemsService.removeItem(id);
};
}]); app.factory('ItemsService', ['$firebase', 'FIREBASE_URI', function ($firebase, FIREBASE_URI) {
var ref = new Firebase(FIREBASE_URI);
var items = $firebase(ref); var getItems = function () {
return items;
}; var addItem = function (item) {
items.$add(item);
}; var updateItem = function (id) {
items.$save(id);
}; var removeItem = function (id) {
items.$remove(id);
}; return {
getItems: getItems,
addItem: addItem,
updateItem: updateItem,
removeItem: removeItem
}
}]);
You can lisisten to the 'loaded', 'chane' events by using
$on('loaded', function(){...}).
You can deattache the events by using
$off() //unattach all events
$off('loaded') //unattach only loaded event
[Firebase] 2. Firebase Event Handling的更多相关文章
- Event Handling in Spring
Spring内置的event有 1.ContextRefreshedEvent This event is published when the ApplicationContext is eithe ...
- [转]Getting started with SSIS - Part 10: Event Handling and Logging
本文转自:http://beyondrelational.com/modules/12/tutorials/24/tutorials/9686/getting-started-with-ssis-pa ...
- Console Event Handling
http://www.codeproject.com/Articles/2357/Console-Event-Handling Console Event Handling Kumar Gaurav ...
- 理解iOS Event Handling
写在前面 最近的一个iOS App项目中遇到了这么问题:通过App访问服务器的大多数资源不需要登录,但是访问某些资源是需要用户提供验证的,一般来说,通常App的做法(譬如美团App)将这些资源放在“我 ...
- Event Handling Guide for iOS--(三)---Event Delivery: The Responder Chain
Event Delivery: The Responder Chain 事件传递:响应链 When you design your app, it’s likely that you want to ...
- Event Handling Guide for iOS--(二)---Gesture Recognizers
Gesture Recognizers 手势识别器 Gesture recognizers convert low-level event handling code into higher-leve ...
- Event Handling Guide for iOS--(一)--About Events in iOS
About Events in iOS Users manipulate their iOS devices in a number of ways, such as touching the scr ...
- UI Framework-1: Aura Event Handling
Event Handling A diagram of the architecture of this system: HWNDMessageHandler owns the WNDPROC ...
- Event Handling Guide for iOS(五)
基本概念: 加速计: 又称加速度计,测量设备运动的加速度. 加速度: 矢量,描绘速度的方向和大小变化的快慢. 陀螺仪: 感测与维持方向的装置. 原文: Motion Event声明: 由于本人水平有限 ...
随机推荐
- Android升级ADT22后会报ClassNotFoundException的原因分析
http://blog.csdn.net/huzgd/article/details/8962702 1.ADT16下,只要add to path就是add to path并export:2.ADT2 ...
- js基本数据类型 BigInt 和 Number 的区别
今天在做LeetCode的一到 “加一” 的题,题目如下 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除 ...
- Chris and Magic Square CodeForces - 711B
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid o ...
- JAVA中关于大数问题
这里只是java速成,只限于java语法,包括输入输出,运算处理,字符串和高精度的处理,进制之间的转换等,能解决OJ上的一些高精度题目. 一.样例:java中的输出a+b import java.io ...
- setResult()的调用时机
今天遇到这样一个问题,我在Activity-A中用startActivityForResult()方法启动了Activity-B,并且在B中通过setResult()方法给A返回值,由于某些原因不能在 ...
- 80.Vigenère密码(模拟)
Vigenère密码(文件名vigenere.cpp vigenere.in vigenere.out) 题目描述 Description 16 世纪法国外交家Blaise de Vigen ...
- CentOS下使用KVM克隆虚拟机自动修改网卡的MAC地址
克隆完虚拟机之后Mac地址还保留着母机的配置,此时需要修改成新的Mac地址才能继续,网上一般都是这样的手动操作: 参考:http://blog.51cto.com/freedyong/1361907 ...
- Spartan-6 FPGA Configuration
These configuration pins serve as the interface for a number of different configuration modes: • JTA ...
- TPS5410/TPS5430 开关电源稳压器(DC-DC)
- 修改gnome-shell扩展“Applications Menu”的菜单区域宽度。
sudo打开 /usr/share/gnome-shell/extensions/apps-menu@gnome-shell-extensions.gcampax.github.com/extensi ...