|
import { Component, OnInit } from '@angular/core'; |
|
import { Product } from '../shared/models/character'; |
|
import { ProductService } from './character.service'; |
|
|
|
@Component({ |
|
selector: 'product-list', |
|
templateUrl: './app/products/product-list.component.html', |
|
providers: [ProductService] |
|
}) |
|
|
|
export class CharacterListComponent implements OnInit { |
|
products:Character[]; |
|
|
|
constructor(private productService: ProductService) {} //if i use constructor i get: "cannot resolve all parameters" error |
|
//productService = new ProductService(); <- using like this it works, but... you know. |
|
// but then i get "can not read get property of undefined" error in the product service |
|
|
|
errorMessage: string; |
|
|
|
ngOnInit(): void { |
|
this.productService.getAll(). |
|
subscribe(products => this.products = products, |
|
error => this.errorMessage = <any>error); |
|
} |
|
} |