[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声明: 由于本人水平有限 ...
随机推荐
- Python编程举例-自定义日期格式
#自定义格式 x = '{0}{0}{0}'.format('dog') print(x) class Date: def __init__(self,year, mon,day): self.yea ...
- 验证码无法显示:Could not initialize class sun.awt.X11GraphicsEnvironment 解决方案
一.原因现象:图下图 二.原因导致: 经过Google发现很多人也出现同样的问题.从了解了X11GraphicEnvironment这个类的功能入手,一个Java服务器来处理图片的API基本上是需要运 ...
- Django+Nginx+uwsgi搭建自己的博客(一)
最近对写爬虫有些厌倦了,于是将方向转移到了Web开发上.其实在之前自己也看过一部分Flask的资料,但总觉得Flask的资料有些零散,而且需要的各种扩展也非常多.因此,我将研究方向转移到了另一个主流的 ...
- Properties Editor 中文编辑器 汉化
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 在Eclipse的 [Help]-> [ Install New Software ...
- asp.net绝对与相对路径
对于asp.net 路径的问题,闲心有很多人和我一样,只是知道一点,理解并不深刻.下面我就来整理一下相路径和绝对路径的知识. 绝对路径: 每个网页都有一个唯一的地址,它就是该网页的绝对路径.绝对路径提 ...
- POJ 2378 Tree Cutting 3140 Contestants Division (简单树形dp)
POJ 2378 Tree Cutting:题意 求删除哪些单点后产生的森林中的每一棵树的大小都小于等于原树大小的一半 #include<cstdio> #include<cstri ...
- [Codeforces #201] Tutorial
Link: 传送门 代码量很少的一套思维题 A: 试一试发现最后状态一定是所有$min,max$间$gcd$的倍数 直接判断数量的奇偶性即可 #include <bits/stdc++.h> ...
- 【左偏树+贪心】BZOJ1367-[Baltic2004]sequence
[题目大意] 给定一个序列t1,t2,...,tn ,求一个递增序列z1<z2<...<zn , 使得R=|t1−z1|+|t2−z2|+...+|tn−zn| 的值最小.本题中,我 ...
- maven搭建企业级多模块项目
1.创建一个maven项目 选择pom 完成 2.创建模块 项目右键选择module,创建模块.创建子模块 其余的打包时都为jar 地址:https://github.com/LeviFromCN/m ...
- servlet3.0 @WebServlet注解无效的情况
web.xml文件中的metadata-comcomplete属性的作用: 该属性指定当前的部署描述文件是否是完全的.如果设置为true,则容器在部署时只依赖部署描述文件,忽略所有的注解(同时也会跳过 ...