[英]Jhipster entity how to use it on page
我正在學習一些全棧的東西。 我創建了一個 JHipster 項目並創建了一個名為 Post 的實體,其中我有一些字段,例如主題、正文和帖子作者的姓名。 Model 正在工作,我可以添加新帖子。 問題是我想把實體放在主頁上,就像博客一樣。 這是我的主頁:
<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>
這是我的 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() 是從一個教程中復制的,該教程是版本 4 中的 angular,我的是 9,它不工作。 我添加了一個 class 響應包裝器,但我不確定我應該放什么,誰能告訴我如何開始這樣的任務? 響應應該是怎樣的。 我正在粘貼響應包裝器,但我知道它無效。
export class ResponseWrapper {
constructor(
public headers: Headers,
public json: any,
public status: number
) { }
}
謝謝你的幫助!
請改用 HttpResponse。
loadAll(): void {
this.postService.query().subscribe(
(res: HttpResponse<any>) => {
// console.log(res);
this.posts = res.body;
},
(res: HttpResponse<any>) => {
// console.log(res);
}
);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.