【发布时间】:2020-07-11 19:00:11
【问题描述】:
我必须在管道中捕获事件发射器的事件发射,并在此基础上执行一些操作。
下面是html和ts文件的sn-p代码
xyx.component.html
<div *ngIf="count | async as count">
<div style="text-align: center">
<div>{{ count.counter }}</div>
<div>
<input type="button" value="start" (click)="start.emit()">
<input type="button" value="stop" (click)="stop.emit()">
</div>
</div>
</div>
xyx.component.ts
@Component({
selector: 'xyz-app',
templateUrl: './xyz.component.html',
styleUrls: ['./xyz.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class XYZComponent {
public readonly count: Observable<{
counter: number,
}>;
public readonly start: EventEmitter<void> = new EventEmitter();
public readonly stop: EventEmitter<void> = new EventEmitter();
constructor() {
this.count = interval(1000).pipe(
map(counter => counter + 1),
startWith(0),
map(counter => ({counter})),
);
}
}
我应该在管道中做什么来捕获该事件发出并执行计数器的启动和停止操作。
【问题讨论】:
标签: angular rxjs pipe rxjs-pipeable-operators