admin管理员组文章数量:1426938
Using Angular2 I'm trying to make a list from an array...something like:
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: `
<ul>
<li *ngFor="">
{{names}}
</li>
</ul>
`,
})
export class AppComponent {
names = ['name1', 'name2', 'name3'];
}
How can I get something like this to work?
Using Angular2 I'm trying to make a list from an array...something like:
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: `
<ul>
<li *ngFor="">
{{names}}
</li>
</ul>
`,
})
export class AppComponent {
names = ['name1', 'name2', 'name3'];
}
How can I get something like this to work?
Share Improve this question asked Apr 11, 2016 at 22:23 Satch3000Satch3000 49.5k90 gold badges225 silver badges349 bronze badges 1-
Did you really have this problem? I would think any documentation with NgFor would demonstrate how to do this. I.e., I think it would take you longer to post this question then it would to find the answer with a simple Internet search. Questions are supposed to show some research effort. Obviously you know that something like
#ngFor=""
isn't going to work. You should show what you tried, and where you got stuck, or why you couldn't figure this out based on some documentation. – Mark Rajcok Commented Apr 12, 2016 at 14:51
2 Answers
Reset to default 7Should be
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: `
<ul>
<li *ngFor="#name of names">
{{name}}
</li>
</ul>
`,
})
export class AppComponent {
names = ['name1', 'name2', 'name3'];
}
If you came here looking for Angular Framework v2's syntax - not AngularJS v2 like me here it is:
<ul>
<li *ngFor="let name of names;">
{{name}}
</li>
</ul>
Not saying anyone did anything wrong in the question or anything, their versioning and angular v.s. older angularjs is confusing IMO
本文标签: javascriptAngular2 create a list from arrayStack Overflow
版权声明:本文标题:javascript - Angular2 create a list from array - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745439691a2658389.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论