ngFor* 未在 Angular 5 中从 REST 端点返回数据
ngFor* not returning data from REST endpoint in Angular 5
所以我尝试使用 ngFor* 将 REST 数据提取到我的 html 但我没有得到任何数据。我不确定发生了什么,因为它看起来与我遵循的示例相似。我试图在导航栏中拉出一些下拉菜单,但由于这不起作用,我现在进行了简化。这是我的 ngFor*
<ul class="list-group">
<li *ngFor="let conference of conferenceList" class="list-group-item">
<ul>{{conference.conferenceName}}</ul>
</li>
</ul>
会议服务:
import { HttpClient } from "@angular/common/http";
import {EventEmitter, Injectable} from "@angular/core";
import {Observable} from "rxjs/Observable";
import {Conference} from "./conference.model";
@Injectable()
export class ConferenceService {
onConferenceAdded = new EventEmitter<Conference>();
constructor(private http: HttpClient) {
}
getConferences(): Observable<any> {
return this.http.get('/api/conference');
}
}
我的Conference-list组件:
import { Component, OnInit } from '@angular/core';
import {Conference} from "../conference.model";
import {ConferenceService} from "../conference.service";
@Component({
selector: 'app-conferences-list',
templateUrl: './conferences-list.component.html',
styleUrls: ['./conferences-list.component.css']
})
export class ConferencesListComponent implements OnInit {
conferenceList: Conference[] = [];
constructor(private conferenceService: ConferenceService) { }
ngOnInit() {
this.conferenceService.getConferences()
.subscribe(
(conferences: any[]) => {
this.conferenceList = conferences;
},
(error) => console.log(error)
)
}
}
任何帮助将不胜感激,因为我已经研究了一段时间但似乎无法弄清楚。
谢谢
如果您期望 JSON,而不是来自服务的数组
(conferences: any[]) --> 此输入可能有误
改用(conferences: any)
所以我尝试使用 ngFor* 将 REST 数据提取到我的 html 但我没有得到任何数据。我不确定发生了什么,因为它看起来与我遵循的示例相似。我试图在导航栏中拉出一些下拉菜单,但由于这不起作用,我现在进行了简化。这是我的 ngFor*
<ul class="list-group">
<li *ngFor="let conference of conferenceList" class="list-group-item">
<ul>{{conference.conferenceName}}</ul>
</li>
</ul>
会议服务:
import { HttpClient } from "@angular/common/http";
import {EventEmitter, Injectable} from "@angular/core";
import {Observable} from "rxjs/Observable";
import {Conference} from "./conference.model";
@Injectable()
export class ConferenceService {
onConferenceAdded = new EventEmitter<Conference>();
constructor(private http: HttpClient) {
}
getConferences(): Observable<any> {
return this.http.get('/api/conference');
}
}
我的Conference-list组件:
import { Component, OnInit } from '@angular/core';
import {Conference} from "../conference.model";
import {ConferenceService} from "../conference.service";
@Component({
selector: 'app-conferences-list',
templateUrl: './conferences-list.component.html',
styleUrls: ['./conferences-list.component.css']
})
export class ConferencesListComponent implements OnInit {
conferenceList: Conference[] = [];
constructor(private conferenceService: ConferenceService) { }
ngOnInit() {
this.conferenceService.getConferences()
.subscribe(
(conferences: any[]) => {
this.conferenceList = conferences;
},
(error) => console.log(error)
)
}
}
任何帮助将不胜感激,因为我已经研究了一段时间但似乎无法弄清楚。 谢谢
如果您期望 JSON,而不是来自服务的数组
(conferences: any[]) --> 此输入可能有误
改用(conferences: any)