赞
踩
用途是 一个按钮,如果在一定时间内连续点击,只会执行最后一次点击的事件。
写一个按钮:
<div>
<button (click)="demo()">demo</button>
</div>
ts:
public subject = new Subject() constructor() { } ngOnInit() { this.subject.pipe(debounceTime(500)).subscribe(() => { console.log(11) } ) } public demo() { console.log(22) this.subject.next() }
控制台:
单次点击:
多次点击:
点了8次按钮,console出8个22,但只有一个11。
.pipe()的写法好像是angular6(记不清了)以后的写法,之前的版本不用加pipe。
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。