I am learning some fullstack stuff. I created a JHipster project and created an entity called Post, in which i have a few fields like subject, body and name of author of the post. Model is working i can add new Posts. The thing is i wanna put entity on home page in a block like a Blog. This is my homepage:
<div class="row">
<div class="col-md-3">
<span class="hipster img-fluid rounded"></span>
</div>
<div class="col-md-9">
<h1>Welcome to JBlog!</h1>
<div *ngFor="let post of posts">
<h2>{{post.title}}</h2>
<p [innerHTML]="post.body"></p>
<small>Written By: {{post.author}}</small>
<hr/>
</div>
</div>
</div>
and here is my component.ts
import { Component, OnInit, OnDestroy } from '@angular/core';
import {Post} from "app/shared/model/post.model";
import {PostService} from "app/entities/post/post.service";
import {ResponseWrapper} from "app/shared/model/response-wrapper.model";
@Component({
selector: 'jhi-home',
templateUrl: './home.component.html',
styleUrls: ['home.scss'],
})
export class HomeComponent implements OnInit {
posts: Post[] = [];
constructor(private postService: PostService) {
}
ngOnInit() {
console.log("ngOnInit...")
this.loadAll();
}
loadAll() {
this.postService.query().subscribe(
(res: ResponseWrapper) => {
console.log(res.json);
this.posts = res.json;
},
(res: ResponseWrapper) => {
console.log(res.json);
}
);
}
}
function loadAll() is coppied from a tutorial which was a angular in version 4, mine is 9 and it not working. I added a class response-wrapper, but im not sure what i should put there, Could anyone tell me how to begin with such task? How the response should be looks like. I'm pasting the response-wrapper but i know its invalid.
export class ResponseWrapper {
constructor(
public headers: Headers,
public json: any,
public status: number
) { }
}
Thanks for any help!
Use HttpResponse instead.
loadAll(): void {
this.postService.query().subscribe(
(res: HttpResponse<any>) => {
// console.log(res);
this.posts = res.body;
},
(res: HttpResponse<any>) => {
// console.log(res);
}
);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.