Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class ProductService {
- public products: Product[];
- constructor(private http: HttpClient) { }
- init(): any {
- if (!this.products) {
- this.http.get<Product[]>("https://my-api.com/GetAllProducts").subscribe(products => {
- this.products = products;
- });
- }
- }
- }
- getProductFromProductId(productId: string) {
- return this.products.find(x => x.id === productId);
- }
- getProductFromProductId(productId: string) {
- if(!this.products) {
- setTimeout(() => {
- console.log("Products not loaded yet");
- getProductFromProductId(productId);
- }, 10);
- } else {
- return this.products.find(x => x.id === productId);
- }
- }
Add Comment
Please, Sign In to add comment