Questions tagged «ngfor»

8
ngFor,其中索引作为属性中的值
我有一个简单的ngFor循环,它也跟踪当前情况index。我想将该index值存储在属性中,以便可以打印它。但我不知道这是如何工作的。 我基本上有这个: <ul *ngFor="#item of items; #i = index" data-index="#i"> <li>{{item}}</li> </ul> 我想#i在属性中存储的值data-index。我尝试了几种方法,但没有一种起作用。 我在这里有一个演示:http : //plnkr.co/edit/EXpOKAEIFlI9QwuRcZqp?p=preview 如何将index值存储在data-index属性中?
570 angular  ngfor 

15
* ngIf和* ngFor在同一元素上导致错误
我在与试图使用角度的问题*ngFor,并*ngIf在相同的元素。 当尝试遍历中的集合时*ngFor,该集合被视为null,因此在尝试访问其在模板中的属性时失败。 @Component({ selector: 'shell', template: ` <h3>Shell</h3><button (click)="toggle()">Toggle!</button> <div *ngIf="show" *ngFor="let thing of stuff"> {{log(thing)}} <span>{{thing.name}}</span> </div> ` }) export class ShellComponent implements OnInit { public stuff:any[] = []; public show:boolean = false; constructor() {} ngOnInit() { this.stuff = [ { name: 'abc', id: 1 }, { name: 'huo', …

13
例外:无法绑定到“ ngFor”,因为它不是已知的本机属性
我究竟做错了什么? import {bootstrap, Component} from 'angular2/angular2' @Component({ selector: 'conf-talks', template: `<div *ngFor="talk of talks"> {{talk.title}} by {{talk.speaker}} <p>{{talk.description}} </div>` }) class ConfTalks { talks = [ {title: 't1', speaker: 'Brian', description: 'talk 1'}, {title: 't2', speaker: 'Julie', description: 'talk 2'}]; } @Component({ selector: 'my-app', directives: [ConfTalks], template: '<conf-talks></conf-talks>' }) class …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.