I am trying to create a CRUD application that works a bit like a blog. I have all of the create, read, update, and delete functions working. I want to display only one object's data (example: title, description) based on the ID of the object which is part of the route (localhost:4200/route/0).
I can get the data to display the way I want using <input [(ngModel)]"articles.title">, but not using ngFor on <h1> or any other tag.
app-routing-module.ts
{ path: 'article/:id', component: ArticleComponent}
db.json
"articleInfo": [
{
"id": 0,
"title": "Marinara Pasta",
"category": "Italian",
"author": "Sample",
"date": "06/11/2019",
"description": "A classic Italian dish. Quick, easy, and ready to eat in only 15 minutes.",
"image": "/assets/sample.png"
}
]
data.service.ts
baseUrl:string = "http://localhost:3000";
getData(id: number): Observable<Data> {
return this.http.get<Data>(this.baseUrl + '/articleInfo/' + id)
}
article.component.ts
export class ArticleComponent implements OnInit {
id = this.actRoute.snapshot.params['id'];
articles: any = [];
constructor(private dataService: DataService, public actRoute: ActivatedRoute, public router: Router) { }
loadIdData() {
return this.dataService.getData(this.id).subscribe(data => {
this.articles = data;
})
}
ngOnInit() {
this.loadIdData();
}
}
article.component.html
<div *ngFor="let info of articles">
<h2> {{info.title}} </h2>
<h6> {{info.description}}</h6>
</div>
I get ERROR and ERROR CONTEXT in ArticleComponent.ngfactory.js.