角RxJS:Subject <void> .asObservable()返回未定义

时间:2019-05-06 14:27:32

标签: angular rxjs

我创建了Subject来填充一些事件点击:

<button type="search" class="btn btn-primary" (click)="search()">
    <i class="fa fa-search" aria-hidden="true"></i> Cercar
</button>

我的组件是:

private searchClickSubject:Subject<void>;
private searchClick$:Observable<void>;

constructor() {
    this.searchClickSubject = new Subject<void>();
    this.searchClick$ = this.searchClickSubject.asObservable();   <<<1>>>
}

private search(): void {
    this.searchClickSubject.next();
}

尽管如此,在<<<1>>>this.searchClick$ = this.searchClickSubject.asObservable();之后,它会返回undefined

有什么想法吗?

0 个答案:

没有答案