【发布时间】:2017-08-22 01:34:05
【问题描述】:
提前感谢您的时间,我正在尝试显示我从本地 mongodb 集合中提取的集合。 http://localhost:8080/player/all 是 API 端点,当我使用 postmaster 对其进行测试时,它会返回正确的数据。它是一个对象数组。 HTML 仅显示每个对象的 [object Object],例如:
[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象]
服务或组件有问题吗?
后端是一个 express/node 应用程序
player.component.html
<div> {{allPlayers}} </div>
player.component.ts
import { Component, OnInit } from '@angular/core';
import {AuthService} from '../../services/auth.service';
import {PlayerService} from '../../services/player.service';
import {Router} from '@angular/router';
@Component({
selector: 'app-player',
templateUrl: './player.component.html',
styleUrls: ['./player.component.css']
})
export class PlayerComponent implements OnInit {
allPlayers: Array<Object>;
constructor(private authService:AuthService,
private router:Router,
private playerService: PlayerService) { }
ngOnInit() {
this.playerService.getAllPlayers().subscribe(allPlayers => {
this.allPlayers = allPlayers;
},
err => {
console.log(err);
return false;
});
}
}
player.service.ts
import { Injectable } from '@angular/core';
import {Http, Headers} from '@angular/http';
@Injectable()
export class PlayerService {
constructor(private http:Http) {
}
getAllPlayers(){
return this.http.get("http://localhost:8080/player/all")
.map(res => res.json());
}
}
【问题讨论】: