[英]Jhipster entity how to use it on page
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.
我创建了一个 JHipster 项目并创建了一个名为 Post 的实体,其中我有一些字段,例如主题、正文和帖子作者的姓名。 Model is working i can add new Posts.
Model 正在工作,我可以添加新帖子。 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这是我的 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. function loadAll() 是从一个教程中复制的,该教程是版本 4 中的 angular,我的是 9,它不工作。 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?
我添加了一个 class 响应包装器,但我不确定我应该放什么,谁能告诉我如何开始这样的任务? 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.请改用 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.