这件事真让我心烦。我试着用2/4角显示一个数组,我认为角度上有一个错误。html、服务或组件部分,因为我的节点后端正常工作。我的html看起来像这样。
<div class = "container">
<li *ngFor = "let customer of customers">
<div class = "col md-6">
{{ customer.firstName }}
</div>
</li>
<div *ngFor = "let customer of customers">
<div class = "col md-6">
{{ customer.lastName }}
</div>
</div>我的服务是这个
@Injectable()
export class CustomerService {
constructor(private http: Http) { }
//retreiving custmers
getCustomers(){
return this.http.get('http://localhost:3001/api/customers')
.map(res => res.json());
}
}我的组件是
export class CustomersComponent implements OnInit {
customers: Customer[];
customer: Customer;
firstName: string;
lastName: string;
//initialize customer service
constructor(private customerService: CustomerService) { }
//initiated once component is loaded
ngOnInit() {
this.customerService.getCustomers()
.subscribe( customer =>
this.customer = customer);
}发布于 2017-05-18 23:53:00
您有一个错误,将customer更改为customers
this.customerService.getCustomers()
.subscribe( customers => {
this.customers = customers
});
}https://stackoverflow.com/questions/44059000
复制相似问题