node.js - 尝试使用假 JSON 数据,但无法在 HTML 页面中更新

标签 node.js angular rest angular-services

数据已显示,但不知道为什么无法按照语法和代码获取图像。

The data is been displayed but I don't know why I'm not able to get the images as per the syntax and code

<h2>Amazing Places on Earth</h2>


<div class="card">
    <div class=" card-block">
        <img src="{{post.url}}" class="img-fluid ${3|rounded-top,rounded-right,rounded-bottom,rounded-left,rounded-circle,|}" style="width :300px" alt="paris">
        <div class="card-titile">
            {{post.title}}
        </div>
        <div class="card-text">
            <p>Get details Click find more</p>
        </div>
        <a href="#" class=" btn btn-success"> Find More</a>
    </div>
</div>

这是迄今为止我在组件中使用的使用 bootstrap 4 代码的 HTML。

请在下面找到(获取)请求代码。此外,我正在使用 Angular 的最新版本

@Component({
  selector: 'app-places',
  templateUrl: './places.component.html',
  styleUrls: ['./places.component.css']
})
export class PlacesComponent implements OnInit {    
  constructor(private data: PhotodataService) { }
  posts: object;
  ngOnInit() {
    this.data.getdata().subscribe(data => {
      this.posts = data;
      console.log(this.posts);
    });
  }    
}

最佳答案

您缺少*ngFor来自您的组件

<!-- notice the *ngFor below -->
<div *ngFor="let post of posts" class="card">
    <div class=" card-block">
        <img src="{{post.url}}" class="img-fluid ${3|rounded-top,rounded-right,rounded-bottom,rounded-left,rounded-circle,|}" style="width :300px" alt="paris">
        <div class="card-titile">
            {{post.title}}
        </div>
        <div class="card-text">
            <p>Get details Click find more</p>
        </div>
        <a href="#" class=" btn btn-success"> Find More</a>
    </div>
</div>

基本上这意味着循环所有帖子并为每个帖子创建一个卡片

关于node.js - 尝试使用假 JSON 数据,但无法在 HTML 页面中更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59241819/

相关文章:

node.js - 在 Sequelize 迁移中定义部分索引?

javascript - Node.js 和 postgres 听

javascript - Node.js Express、路由器、可选参数作为扩展

javascript - 查询mongodb中的javascript日期对象

javascript - angular 2复选框选择全部

没有 ng-template 的 Angular ngx-bootstrap 模型

html - 为什么我的导航栏没有覆盖整个屏幕?

java - 当路径中的第一个缺失时,多个 PathParams 不会失败

node.js - 使用 node.js supertest 对 multipart/form-data 进行 POST

rest - 保护对 Kafka Connect 的 REST API 的访问