我希望在控制台窗口中打印以下值:
0 10 20 30 40
我越来越 0 1个 2 3 4
import { Component } from '@angular/core';
import { interval, timer } from 'rxjs'
import { take, map } from 'rxjs/operators';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
导出类AppComponent { mySubject $ ngOnInit(){ //每1秒发射一次值 const source = interval(1000);
//when timer emits after 5s, complete source
const numbers$ = source.pipe(take(5));
numbers$
.pipe(map(x => x * 10))
.subscribe(x =>
console.log(x));
}
ngOnDestroy(){
this.mySubject$.unsubscribe();
}
}