0
I’m getting this error message;
This indicating that the error is here;
<!-- INíCIO do CONTEÚDO -->
<section class="content-header">
<h1>
Todos os Restaurantes
</h1>
</section>
<section class="content">
<div class="row">
<div *ngFor="let restaurant of restaurants" class="col-sm-6 col-xs-12">
<mt-restaurant [restaurant]="restaurant"></mt-restaurant>
</div>
</div>
</section>
That’s my kind of services;
@Injectable()
export class RestaurantService {
public url: String = 'http://localhost:3000/api/';
constructor(private http: Http) {
// this.url = environment.url;
}
restaurants(): Observable<Restaurant[]> {
return this.http.get(`${this.url}/restaurants`)
.map(response => response.json())
}
And this is my class of components;
restaurants: Restaurant[]
constructor(private restaurantService: RestaurantService){}
ngOnInit() {
this.restaurantService.restaurants()
.subscribe(restaurants => this.restaurants = restaurants)
}
What could be wrong?
You are passing <mt-Restaurant [Restaurant]="Restaurant"></mt-Restaurant> "Restaurant" and not "Restaurants" which is your array.
– Lucas Brogni
Partner, give a console.log to your Replenisher and see what’s coming back, and tell me here, or print it so we can see the error better. Log tbem into your observable and printa
– Philip Developer
ps: this Http is not the angular one, but probably an HTTP service made "by hand" by the author of the question. Catch for readers...
– wkrueger