2017-05-04 150 views
-3
//appcomponent.ts 
import { Component } from '@angular/core'; 

@Component({ 
    selector: 'app-root', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'] 
}) 
export class AppComponent { 
    heroes=[{name:"superman"},{name:"heman"}]; 
} 
//app.component.html 

<ul><li *ngfor="let hero of heroes">{{hero.name}}</li></ul> 

此代码不起作用,并给我空白输出。如果你有解决方案this.pls让我知道需要ngfor的解决方案

+2

'* ngFor',而不是'* ngfor'? – yurzui

+0

* ngFor not * ngfor – Picci

+0

谢谢picci ... –

回答

-1

你已经完成了一个小的语法错误*ngfor 它遵循骆驼套,其中f必须在captial情况下。

正确的代码下面附:

<ul> 
    <li *ngFor="let hero of heroes"> 
    {{hero.name}} 
    </li> 
</ul>