angularjs - Angular 2服务返回对象对象

标签 angularjs node.js mongodb

提前感谢您的宝贵时间,我正在尝试显示从本地 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());
  }
}

最佳答案

使用 Angular 管

{{allPlayers| json}}

关于angularjs - Angular 2服务返回对象对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43078674/

相关文章:

node.js - Node Mongoose 用于单独查询的单独索引

python - Mongodb复制集自动重新连接在nginx + uwsgi上下运行后无法正常工作

angularjs - 为什么 Controller 中的代码被调用两次?

javascript - 二维数组中的 AngularJS ng-repeat

javascript - CSV 文件作为单个字符串返回

javascript - 两个嵌套循环中的同步调用

javascript - Mongo Node js,如何不返回整个对象文档?

angularjs - angularjs 中的 gettext 模块不会翻译 Controller 中的 gettextCatalog.getString()

node.js - 将 Postgres 与新创建的 React 应用程序一起使用时出错 : Module not found: Can't resolve 'dns'

node.js - 未找到模块 : Can't resolve 'fs' on @google-cloud/storage