Node.js Angular 2*ngFor不打印到表中,我通过GET HTTP调用获取信息,它可以正常工作

Node.js Angular 2*ngFor不打印到表中,我通过GET HTTP调用获取信息,它可以正常工作,node.js,angular,ngfor,Node.js,Angular,Ngfor,你好,我需要帮助 angular2中的我的ngFor未打印到表中 我正在通过GET HTTP调用获取信息,如果我执行*NGO操作,它就会工作,因为它不会显示 这是我的html 这是my formations.ts(schema dans un fichier ts) 这是我的路线 ) 这是我的阵型。模特 试着改变你给的表格中的名字,让形成的形成,而不是作为形成的形式,并尝试它 在component.html中 名称 电子邮件 电话号码 {{list.name} {{list.email} {

你好,我需要帮助 angular2中的我的ngFor未打印到表中 我正在通过GET HTTP调用获取信息,如果我执行*NGO操作,它就会工作,因为它不会显示

这是我的html

这是my formations.ts(schema dans un fichier ts)

这是我的路线

)

这是我的阵型。模特

试着改变你给的表格中的名字,让形成的形成,而不是作为形成的形式,并尝试它

在component.html中


名称
电子邮件
电话号码
{{list.name}
{{list.email}
{{list.phone}

您可以使用异步管道,您不必订阅您的Observable

组件1.ts:

export class FormationsComponent {
  formations: Observable<Formation[]>;
  constructor(private formationService: FormationService){};

  ngOnInit() {
     this.formations = this.formationService.getFormations();
   }
}
导出类格式组件{
形态:可见;
构造函数(私有formationService:formationService){};
恩戈尼尼特(){
this.formations=this.formationService.getFormations();
}
}
在你的html文件中

<tr *ngFor="let formation of formations | async" >


我在angular 2中没有@angular/common/http,请看我的照片。您只能在angular 2中导入http模块,从'@angular/http'导入{HttpModule};httpClient有5个及以上版本
export class Formation{
    title: string;
    url: string;
    description: string;
}
const express = require('express');
const router = express.Router();
const Formation = require('../models/formations');
const mongoose = require('mongoose');
const config = require('../config/database');

   router.get('/', function(req, res){
                Formation.getFormations(function(err,formation){
                    if(err) throw err;
                    res.json(formation);
                });
            })

module.exports = router
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const config = require('../config/database');


var FormationSchema = new mongoose.Schema({
    title: String,
    url : String,
    description : String
},{
    versionKey : false
});




var Formation =  module.exports = mongoose.model('Formation', FormationSchema, 'Formations');
module.exports.getFormations = function(callback){
    Formation.find(callback);
}
<table class="table table-bordered">
  <thead>
    <tr>
      <td><b>Title</b></td>
      <td><b>url</b></td>
      <td><b>description</b></td>
      <td width="275" align="center"><b>Action</b></td>
    </tr>
  </thead>
  <tbody>  
     <tr *ngFor="let forms of formation" >
        <td>{{forms.title}}</td>
        <td>{{forms.url}}</td> 
        <td>{{forms.description}}</td>
        <td width="275"> 
            <a class="btn btn-info" href="">Detail</a> 
            <a class="btn btn-success" href="" >Edit</a>
            <a class="btn btn-danger" href="" >Delete</a>
        </td>
        </tr>

  </tbody>
</table>
export class ContactComponent implements OnInit{   
ContactList: any[];

constructor(  private http: HttpClient){}



addContacts(){
   this.http.get("yourApiHere")
   .subscribe((contacts: any) => {
    this.ContactList = contacts;
    console.log(this.ContactList);
});
}


    ngOnInit(){
      this.addContacts();
    }
                    <div class="table100-head" >
                      <table>
                        <thead>
                          <tr class="row100 head">
                            <th class="cell100 column1">Name</th>
                            <th class="cell100 column2">Email</th>
                            <th class="cell100 column3">Phone Number</th>                    
                          </tr>
                        </thead>
                      </table>
                </div>

                <div class="table100-body js-pscroll">
                    <table>
                        <tbody>
                          <tr class="row100 body" *ngFor="let list of contactList">
                            <td class="cell100 column1" >{{list.name}}</td>
                            <td class="cell100 column2">{{list.email}}</td>
                            <td class="cell100 column3">{{list.phone}}</td>

                          </tr>               
                        </tbody>
                    </table>
                </div>
export class FormationsComponent {
  formations: Observable<Formation[]>;
  constructor(private formationService: FormationService){};

  ngOnInit() {
     this.formations = this.formationService.getFormations();
   }
}
<tr *ngFor="let formation of formations | async" >