Angular 2数据问题 [英] Angular 2 data issue
本文介绍了Angular 2数据问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I have a component which is properly being called from the .ts file but it's still not returning the data.
And have a service
import {Component} from 'angular2/core'
import {AuthorServices} from './author.service'
@Component
({
selector: 'author',
template: `
<h1>Authors</h1>
{{title}}
<ul>
<li ngFor ="#auth of author">
{{auth}}
</li>
</ul>
`,
providers: [AuthorServices]})
export class AuthorComponent{
title ="Name of Author";
authors;
constructor(authorServices : AuthorServices){
this.authors = authorServices.getAuthor();
} }
export class AuthorServices{
getAuthor(): string[]{
return ['Paul','Eva','Nicholas'];
}}
It should return array along with its title. But I am not sure where it's getting stuck. Please Help!
我尝试过:
我尝试更改标签,检查指令以及通过
What I have tried:
I tried changing the tags, checked the directives and also the calls made accross
推荐答案
进行的调用请尝试关注并告诉我如果这不起作用你 -
Please try following and let me know if that doesn't work for you-
<ul>
<li *ngFor="let auth of authors">
{{auth}}
</li>
</ul>
为什么?因为您的数组名称是 authors
而不是 author
。
希望,它有助于:)
Why? Because your array name is authors
and not author
.
Hope, it helps :)
这篇关于Angular 2数据问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文