<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. 更新archlinux

    有个上网本,虽然配置很差,但是安装的是arch,这不长时间不滚动更新出问题了, :: Proceed with installation? [Y/n] (/) checking keys % (/) ...

  2. Codeforces 785D Anton and School - 2(组合数)

    [题目链接] http://codeforces.com/problemset/problem/785/D [题目大意] 给出一个只包含左右括号的串,请你找出这个串中的一些子序列, 要求满足" ...

  3. 【动态规划】【记忆化搜索】【搜索】CODEVS 1262 不要把球传我 2012年CCC加拿大高中生信息学奥赛

    可以暴力递归求解,应该不会TLE,但是我们考虑记忆化优化. 设f(i,j)表示第i个数为j时的方案数. f(i,j)=f(1,j-1)+f(2,j-1)+……+f(i-1,j-1) (4>=j& ...

  4. 【匈牙利算法模板】BZOJ1191-超级英雄

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...

  5. PythonGUI编程--向列表框添加滚动条

    代码如下: from tkinter import * window = Tk() window.title("New England") yscroll = Scrollbar( ...

  6. [Git] Git把Tag推送到远程仓库

    转载: http://blog.csdn.net/hustpzb/article/details/8056518 用git tag来给工程打上标签,但是这个命令只是在本地仓库打标签而已, 为了能把标签 ...

  7. Kubernetes Fluentd+Elasticsearch+Kibana统一日志管理平台搭建的填坑指南

    在初步完成Kubernetes集群架构的建立后,通过搭建一些监控组件,我们已经能够实现 图形化的监控每个node,pod的状态信息和资源情况 通过scale进行replicateSet的扩展和伸缩 通 ...

  8. uCOS-ii笔记

    ucos ii system 文件结构 上层: 应用软件,用户代码 中层: 与处理器无关代码 与应用程序相关配置文件 与处理器有关代码 下层: 硬件(cpu,interupt,timer,gpio,i ...

  9. Spark(四) -- Spark工作机制

    一.应用执行机制 一个应用的生命周期即,用户提交自定义的作业之后,Spark框架进行处理的一系列过程. 在这个过程中,不同的时间段里,应用会被拆分为不同的形态来执行. 1.应用执行过程中的基本组件和形 ...

  10. vue2计算属性computed

    详见vue2.0 API<计算属性> 需求: 模板内的表达式是非常便利的,但是它们实际上只用于简单的运算.在模板中放入太多的逻辑会让模板过重且难以维护.例如: <div id=&qu ...