Home > OS >  how to initialize a observable using typescript with rxjs
how to initialize a observable using typescript with rxjs

Time:10-05

When there is no value, how to initialize a observable value? either i am not set empty value as well.

code :

 interface PropsProduct {
    id: number,
    picture: string,
    price: number,
    name: string,
    combo: boolean,
    discount: number
}

 myArray: Observable<PropsProduct>
  
  constructor(private readonly dataService: DataService) {
    this.myArray = [] //throws the error;
  }

enter image description here

CodePudding user response:

Use of to initiate observable

import { of } from 'rxjs';

this.myArray = of([]);
  • Related