Angular: What's the correct way to return Observable?
问题 I have the following method which isn't working correct: getProducts(): Observable<Product[]> { let PRODUCTS: Product[]; this.http.get(this.base_url + "api/products") .subscribe( (data) => { for(var i in data) { PRODUCTS.push(new Product(data[i].id, data[i].name, data[i].category, data[i].description, data[i].price, data[i].amount)); } }, (error) => { console.log(error); }); return of(PRODUCTS); } The error I'm getting is this: TypeError: Cannot read property 'push' of undefined Now, I know