angular2可观察属性'debouceTime'在类型'Observable< any>'上不存在 [英] angular2 Observable Property 'debouceTime' does not exist on type 'Observable<any>'

查看:76
本文介绍了angular2可观察属性'debouceTime'在类型'Observable< any>'上不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用"angular2 webpack" "angular2/form,Observable" ,但遇到错误,需要帮助..

I use "angular2 webpack" and "angular2/form,Observable" , but met an error ,need help ..

有一个自定义表单验证器-

There is a custom form validator --

import {Observable} from 'rxjs/Rx';
import {REACTIVE_FORM_DIRECTIVES,FormControl, FormGroup, Validators} from '@angular/forms';

emailShouldBeUnique(control:FormControl) {
    return new Observable((obs:any)=> {
      control.valueChanges
        .debouceTime(400)
        .distinctUntilChanged()
        .flatMap(term=>return !this.userQuery.emailExist(term))
        .subscribe(res=> {
            if (!res) {obs.next(null)}
            else {obs.next({'emailExist': true}); }; }
        )});}

我可以找到文件"/projection_direction/node_modules/rxjs/operator/debounceTime.js"

为什么会出现这样的错误-

why is there such the error--

属性"debouceTime"在可观察"类型上不存在.

Property 'debouceTime' does not exist on type 'Observable'.

推荐答案

请确保已在main.ts (启动应用的位置)中启动了该操作

Be sure you've initiated that in main.ts (where the app is bootstraped)

import "rxjs/add/operator/map";
import "rxjs/add/operator/debounceTime";
...

或一次全部

import "rxjs/Rx";

EXTEND

有效的示例

//our root app component
import {Component, EventEmitter, ChangeDetectorRef} from '@angular/core'
import {Observable} from  "rxjs/Rx";
@Component({
  selector: 'my-app',
  providers: [],
  template: `
    <div>
      <h2>Hello {{name}}</h2>

        <div>debounced message: {{message}}</div>
    </div>
  `, 
  directives: []
})
export class App {

  protected message: string;
  protected emitter = new EventEmitter<string>();
  public obs: Observable<string>;

  constructor() {
    this.name = 'Angular2 (Release Candidate!)'

    this.obs = this.emitter
      .map(x => x)
      .debounceTime(1200)
      ;

    this.obs.subscribe(msg => this.message = msg);
  }

  ngOnInit(){
    this.emitter.emit("hello after debounce");
  }
}

并且在main.ts中运行时有效:

and that is working when in main.ts we have:

//main entry point
import {bootstrap} from '@angular/platform-browser-dynamic';
import {App} from './app';

import "rxjs/Rx"; 

bootstrap(App, [])
  .catch(err => console.error(err));

此处

这篇关于angular2可观察属性'debouceTime'在类型'Observable&lt; any&gt;'上不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆