首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ngFor没有在html中显示项目吗?角2/4

ngFor没有在html中显示项目吗?角2/4
EN

Stack Overflow用户
提问于 2017-05-18 22:54:56
回答 1查看 495关注 0票数 0

这件事真让我心烦。我试着用2/4角显示一个数组,我认为角度上有一个错误。html、服务或组件部分,因为我的节点后端正常工作。我的html看起来像这样。

代码语言:javascript
复制
<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>

我的服务是这个

代码语言:javascript
复制
@Injectable()
export class CustomerService {

constructor(private http: Http) { }

//retreiving custmers
getCustomers(){
    return this.http.get('http://localhost:3001/api/customers')
    .map(res => res.json());
}
}

我的组件是

代码语言:javascript
复制
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);


 }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-18 23:53:00

您有一个错误,将customer更改为customers

代码语言:javascript
复制
this.customerService.getCustomers()
    .subscribe( customers => {

        this.customers = customers

      });

 }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44059000

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档