Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component } from '@angular/core';
- import { catchError, map } from 'rxjs/operators';
- import { from, of } from 'rxjs';
- // import { isNumeric } from 'rxjs/internal-compatibility';
- @Component({
- selector: 'fb-root',
- template: ` <H1>Hello Rxjs</H1> `,
- })
- export class AppComponent {
- stream$ = from([5, 10, 15, 'hello', 20]);
- constructor() {
- this.stream$.pipe(
- map(value => {
- // if (isNumeric(value)) { // this is an alternative to the line below
- if (typeof value === 'string') {
- throw new Error("This is not a number")
- } else {
- return value;
- }
- }),
- catchError((err) => of(0)),
- ).subscribe(
- (res) => {
- console.log(res * res)
- },
- err => console.log('Error Occurred', err),
- () => console.log('Stream Completed')
- )
- }
- }
Add Comment
Please, Sign In to add comment