angular响应式编程

1.响应式编程

例子
import {Observable} from "rxjs/Observable";

Observable.from([1,2,3,4])
.filter((item)=>item%2==0)
.map(e=>e*e)
.subscribe(
e=>console.log(e),
err=>console.error(err),
()=>console.log("结束了")
)

例子

延迟400毫秒搜索

1.模块引入

import {FormsModule, ReactiveFormsModule} from "@angular/forms";

imports: [
BrowserModule,
RouterModule.forRoot(routerConfig),
ReactiveFormsModule

],


2. 定义FormControl对象

private searchInput:FormControl = new FormControl();

3.绑定formcontrol对象
<input (keyup)="onKey($event)" [formControl]="searchInput">


4.formControl的值发生改变,就是发射流事件
constructor(private productService:ProductService) {
this.searchInput.valueChanges
.debounceTime(500)
.subscribe(
item=>this.getitem()
)

}

【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/norm/p/8016200.html