<li *ngFor="let fruit of fruitsList; let i = index;">{{i}}-{{fruit.name}}-{{fruit.price}}</li>
<p *ngIf="fruitsList.length > 3">fruitsList's length is bigger than 3</p>

Observable、observer、Subscription
Observable.fromEvent来方便的衔接事件。
常见的链接操作符:concat、merge、combineLates等
投影操作:map、flatMap,flatMap需要重点介绍
过滤:filter、distinctUltilChanges、
操作符分类:Operators by Categories
错误处理:catch、retry、finally
减压:debounce、throttle、sample、pausable
减少:buffer、bufferWithCount、bufferWithTime
如组件:xxx.component.ts、管道:xxx.pipe.ts、服务:xxx.service.ts等
(keyup.enter)
<input (keyup)="onKey($event)">
<input [(ngModel)]="hero.name">
onclick=ng-click=(click)
ng-src=[scr]
map():遍历流
filter():过滤流
do():监视流(通常打个console而已)
catch():捕获异常
subscribe():订阅流(即执行)

this._heroService.getHeroes()
.subscribe(
heroes => this.heroes = heroes,
error => this.errorMessage = <any>error);
this.http.get(this._heroesUrl)
.map(res => <Hero[]> res.json().data)
.do(data => console.log(data)) // eyeball results in the console

1,this[监听器的对象]
2,event.target[当前目标对象]
<ul onclick="test()">
<li></li>
</ul>

1,你按那里都是:
<ul onclick="test()">
<li></li>
</ul>
2,他可能是ul or li

1,this[监听器的对象]
2,event.target[当前目标对象]
<ul onclick="test()">
<li></li>
</ul>

1,你按那里都是:
<ul onclick="test()">
<li></li>
</ul>
2,他可能是ul or li

1,删除fruits数组里的"apples", "oranges" 和 vegetables数组里carrots
{ $pull: { fruits: { $in: [ "apples", "oranges" ] }, vegetables: "carrots" } }
update( { _id: 1 }, { $pullAll: { fruits: [ "apples", "oranges" ] } } )
1.1,删除数组最后一个位置的元素. -1为最前.
$pop: { scores: 1 }

2,数组是json。更新数组里grade<=90 && mean >=80 的std原元为6
{_id: 4,grades: { $elemMatch: { grade: { $lte: 90 }, mean: { $gt: 80 } } }},
{ $set: { "grades.$.std" : 6 } }
{ grade: 85, mean: 90, std: 5 }===>{ grade: 85, mean: 90, std: 6 }.
3, letters添加'["c","d"]' 当一个对像.$addToSet与$push用法一样.$addToSet不添加重复的。
{ $addToSet: {letters: [ "c", "d" ] } }
letters添加 c,d
{ $addToSet: { letters: { $each: [ "c", "d" ] } } }
4,添加数组后倒序,取最前三个. -3取最后三个。
$push: {
quizzes: {
$each: [ { wk: 5, score: 8 }, { wk: 6, score: 7 }, { wk: 7, score: 6 } ],
$sort: { score: -1 },
$slice: 3
}
5,的第二个位置插入
$push: {scores: {$each: [ 20, 30 ],$position: 2}
不为[]
$match: { "inventory_docs": { $ne: [] } }

db.places.aggregate([
{
$geoNear: {
near: { type: "Point", coordinates: [ -73.99279 , 40.719296 ] },
distanceField: "dist.calculated",
maxDistance: 2,
query: { type: "public" },
includeLocs: "dist.location",
num: 5,
spherical: true
}
}
])

==========两次分组
db.campaigns.aggregate([
{ "$match": { "subscriber_id": { "$ne": null } }},

// Count all occurrences
{ "$group": {
"_id": {
"campaign_id": "$campaign_id",
"campaign_name": "$campaign_name",
"subscriber_id": "$subscriber_id"
},
"count": { "$sum": 1 }
}},

// Sum all occurrences and count distinct
{ "$group": {
"_id": {
"campaign_id": "$_id.campaign_id",
"campaign_name": "$_id.campaign_name"
},
"totalCount": { "$sum": "$count" },
"distinctCount": { "$sum": 1 }
}}
])

https://fe.ele.me/let-us-learn-rxjs/
1,
var weight = Rx.Observable.fromEvent(weightSliderElem, 'input')
.map(ev => ev.target.value)
.delay(1000);

var subscription = weight.subscribe(ev => {
weightTextElem.innerHTML = ev;
});

subscription.dispose();
2,
var source = ['1', '1', 'foo', '2', '3', '5', 'bar', '8', '13'];
var result = source
.map(x => parseInt(x))
.filter(x => !isNaN(x))
.reduce((x, y) => x+y);
3,rxjs Time
http://jsbin.com/cafodu/edit?html,js,output
4,signation
https://jsfiddle.net/DrakeLeung/vj368qy7/4/
var windowYOffsetObservable = Rx.Observable.fromEvent(window, 'scroll').map(function () {
// I don't actually care about the event, I just need to get the window offset (scroll position)
return window.pageYOffset;
});

1,page

<!DOCTYPE html>
<html manifest="/m.appcache">
页面ICON image/x-icon|image/gif
<link rel="shortcut icon" href="http://example.com/favicon.ico" type="image/vnd.microsoft.icon">
<link rel="icon" href="http://example.com/favicon.ico" type="image/vnd.microsoft.icon">
<link rel="Bookmark" href="favicon.ico" /> png
预加载
<link rel="prefetch" href="./img/ad/home_03.jpg" />

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">

<meta name="format-detection" content="telephone=no">
<script defer src="myscript.js"></script> async(两个都是异步,加载)defer加载后,等待执行。async下载完就执行。
默认为同步加载,后执行.

2,

<div class="block" #blockOne>
block one
</div>

angular2获得元素方法:
1,
@ViewChild('blockOne') block: ElementRef;
this.block.nativeElement.style.backgroundColor = color;
2,ionic2:
@ViewChild(Content) content: Content;
3,
constructor(public renderer: Renderer,@Inject(DOCUMENT) private document: Document) {}
let toTop = document.getElementById("toTop");
let inputElement = this.renderer.selectRootElement("input");
4,
@Directive({
selector : 'input[type=text][name=txt3]'
})

class Input1 {
constructor(public renderer: Renderer, public elementRef: ElementRef) {

}

focusMe() {

this.renderer.invokeElementMethod(this.elementRef.nativeElement, 'focus', []);
}

}
==
@ViewChild(Input1) input;
http://plnkr.co/edit/3wufGFN4hiJ8JrTsGKxg?p=preview

renderer用法:
https://netbasal.com/angular-2-explore-the-renderer-service-e43ef673b26c#.9c4cbi3vo
let inputElement = this.renderer.selectRootElement("input");
this.renderer.invokeElementMethod(inputElement, “focus”, []);
let inputElement = this.renderer.createElement(this.nativeElement, “input”);
this.renderer.setElementAttribute(inputElement, “value”, “Hello from renderer”);
this.renderer.createText(buttonElement, “Click me!”);
this.renderer.setElementProperty(buttonElement, “disabled”, true);
this.renderer.listen(buttonElement, “click”, ( event ) => console.log(event));
this.renderer.setElementClass(buttonElement, "btn-large", true);
this.renderer.setElementStyle(buttonElement, “backgroundColor”, “yellow”);
https://plnkr.co/edit/8hhUkYQsJTudNuM6wzob?p=preview 动画

[输入型绑定]
1,父亲通过邦定传值给子
<child [(cName)]="pName"></child>
子:
@Input() public cName:string = 'thisIsIgnored';
OR
<my-app-block-two [broadcast]="broadcast1"></my-app-block-two>
broadcast1: EventEmitter;

constructor() {
this.broadcast1 = new EventEmitter<string>();
}
this.broadcast1.emit(color);
子:

@Input() broadcast: EventEmitter;
changeColor(color){
this.block.nativeElement.style.backgroundColor = color;
}

ngOnInit() {
this.broadcast.subscribe((color) => this.changeColor(color));
}
2,子通过邦定传值
<button (click)="changeColor()">Change Color</button>
@Output() colorChanged: EventEmitter;
this.colorChanged.emit(color);

<my-app-block-one (colorChanged)="onChanged($event)"></my-app-block-one>
http://blog.csdn.net/qq_15096707/article/details/52859110

rxjs1的更多相关文章

  1. rxjs2学习

    学习一个东西,一定不要管他怎么实现的,先详细的了解他的使用方法. 这篇博客的作用是都点到,书越读越薄,但是不详细阐述.为了记忆.如果想知道更详细,只能看相关的博客. 也是把以前看到的东西能串连起来. ...

随机推荐

  1. 【动态规划】Codeforces Round #392 (Div. 2) D. Ability To Convert

    D. Ability To Convert time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. 权限管理-RBAC

    (一)RBAC 通过用户与角色关联,角色与操作的关联实现用户与操作的关联 (二)权限细分 (三)数据库设计 (四)程序设计 (五)权限与应用程序 (1)应用URL实现程序权限控制 (2)应用code实 ...

  3. 如何移除inline-block元素之间的空白

    我们想要的是<li>元素可以紧贴在一起,但是很显然,结果“出乎意料”.那么有什么方法可以让结果符合我们的预期呢?所能想到的解决方法至少有以下四种,而每种方法也都有其优劣所在,至于要如何选择 ...

  4. 理解面向对象编程---C#控制台实现52张扑克牌的分法

    52张牌随机分给4个玩家,要求每个玩家的牌用一个一维数组表示. 我们采用模拟大法.初始化一副扑克牌,洗牌,发牌. using System; using System.Collections.Gene ...

  5. webpack配置构建环境问题汇总

    环境:node 6.9.5  npm 3.10.10 问题一:Module build failed: TypeError: Path must be a string. Received undef ...

  6. Xcode编译错误和警告汇总

    1.error: macro names must be identifiers YourProject_prefix.pch 原因: 因为你弄脏了预处理器宏,在它处于<Multiple Val ...

  7. nodeJs+socket.io

    1.先安装npm和node 2.安装socket.io npm install socket.io 3.html <!DOCTYPE html> <html lang="e ...

  8. 关于constraint 的disable和enable

    建立主外键的constraint create table emp1(emp_no number(2) constraint emp_emp_no_pk primary key,ename varch ...

  9. 8、面向对象class

    对象的概念同其他语言的对象相同 一个基本的类 #!/usr/bin/python class person: def hi(self,name): print 'Hello,%s'%name p1= ...

  10. Linux中断(interrupt)子系统之一:中断系统基本原理

    这个中断系列文章主要针对移动设备中的Linux进行讨论,文中的例子基本都是基于ARM这一体系架构,其他架构的原理其实也差不多,区别只是其中的硬件抽象层.内核版本基于3.3.虽然内核的版本不断地提升,不 ...