I have a function which returns Observable but I want to pipe this Observable and apply filter function and interval to emit one Person each 2 seconds. Can anyone tell me how excatly pipe operator works in this case?
PersonService.ts
constructor() {
this.initPersonArray();
}
init(): Observable<Person> {
return Observable.create(obs => {
this.persons.forEach(el => {
obs.next(el);
});
});
}
initPersonArray(): Person[] {
this.persons.push(
new Person('Michal', 'Kowlaski', 24, new Array('plywanie', 'pilka nozna'), Sex.MALE),
new Person('Stefan', 'Kowlaski', 20, new Array('plywanie', 'pilka nozna'), Sex.MALE),
new Person('Jacek', 'Kowlaski', 54, new Array('plywanie', 'pilka nozna'), Sex.MALE),
new Person('Małgorzata', 'Kowlaski', 52, new Array('plywanie', 'pilka nozna'), Sex.FEMALE),
new Person('Katarzyna', 'Kowlaski', 84, new Array('plywanie', 'pilka nozna'), Sex.FEMALE),
new Person('Jan', 'Kowlaski', 86, new Array('plywanie', 'pilka nozna'), Sex.MALE),
);
return this.persons;
}
Then in component I call this function by
ngOnInit(): void {
this.personService.init().subscribe(res => {
console.log('----->', res);
});
}
this.personService.init().pipe(filter(...)).intervalis not an filter, it's function that returns and Observable. Maybe you wantdelayinstead?