I am getting above error in
homes.component.html
when running Angular project to display list of homes from JSON file.
Json File
[
{
"image_url": "https://images.unsplash.com/photo-1460317442991-0ec209397118?auto=format&fit=crop&w=500&q=80",
"type": "Apartment",
"location": "New York",
"title": "Superb duplex apartment in the historical centre"
},
{
"image_url": "https://images.unsplash.com/photo-1480074568708-e7b720bb3f09?auto=format&fit=crop&w=500&q=80",
"type": "House",
"location": "San Francisco",
"title": "Charming house with woodstove"
},
{
"image_url": "https://images.unsplash.com/photo-1522771739844-6a9f6d5f14af?auto=format&fit=crop&w=500&q=80",
"type": "Room",
"location": "New York",
"title": "Nice Clean Room in Brownstone Studio"
},
{
"image_url": "https://images.unsplash.com/photo-1522771739844-6a9f6d5f14af?auto=format&fit=crop&w=500&q=80",
"type": "Room",
"location": "San Francisco",
"title": "Bright and Sunny Shared Room in Downtown"
},
{
"image_url": "https://images.unsplash.com/photo-1480074568708-e7b720bb3f09?auto=format&fit=crop&w=500&q=80",
"type": "House",
"location": "Boston",
"title": "Cape Cod Style House on South Shore"
},
{
"image_url": "https://images.unsplash.com/photo-1522771739844-6a9f6d5f14af?auto=format&fit=crop&w=500&q=80",
"type": "Room",
"location": "San Francisco",
"title": "Large Private Room Facing Golden Bridge"
},
{
"image_url": "https://images.unsplash.com/photo-1480074568708-e7b720bb3f09?auto=format&fit=crop&w=500&q=80",
"type": "House",
"location": "New York",
"title": "Single Family House in Quincy"
},
{
"image_url": "https://images.unsplash.com/photo-1522771739844-6a9f6d5f14af?auto=format&fit=crop&w=500&q=80",
"type": "Room",
"location": "Boston",
"title": "Small Clean Room near Boston University in Brookline"
},
{
"image_url": "https://images.unsplash.com/photo-1480074568708-e7b720bb3f09?auto=format&fit=crop&w=500&q=80",
"type": "House",
"location": "San Francisco",
"title": "Beach House near Restaurants"
},
{
"image_url": "https://images.unsplash.com/photo-1460317442991-0ec209397118?auto=format&fit=crop&w=500&q=80",
"type": "Apartment",
"location": "New York",
"title": "Rustic Apartment in Downtown"
}
]
homes.component.html
<div class="uk-container uk-padding">
<h1>Homes</h1>
<div *ngFor="let home of homes$ | async">
<div class="uk-card">
<div class="uk-card-media-top">
<img src="{{ home.image_url}}">
</div>
<div class="uk-card-body">
<div>
{{ home.type}} / {{ home.location}}
</div>
<div>
{{ home.title}}
</div>
</div>
</div>
</div>
data.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class DataService {
constructor(private httpClient: HttpClient) { }
getHomes() {
return this.httpClient.get('assets/homes.json');
}
}
homes.component.ts
import { Component, OnInit } from '@angular/core';
import { DataService } from '../data.service';
@Component({
selector: 'app-homes',
templateUrl: './homes.component.html'
})
export class HomesComponent implements OnInit {
homes$ = this.dataService.getHomes();
constructor(private dataService: DataService) { }
ngOnInit() {
}
}
I am trying to display the list of homes from JSON file with image and some description under it.