2016-11-19 88 views
1

我是新來的角2我寫的代碼,用於顯示電影列表中顯示一個清單,但它顯示錯誤,請檢查我的代碼...在納克在角2

下面

是我的代碼

component.ts:文件

import { Component} from '@angular/core'; 
@Component({ 
    selector:'my-app', 
    template:`<h1>welcome to my shop</h1> 
    <p>we have the following movies available</p> 
    <div> 
    <p *ngfor=#movie of movieList>{{movie}}</p> 
    </div>` 
}) 
export class MyShopComponent{ 
    public movieList=['batman vs superman','civil war','deadpool'] 
} 

app.module.ts:文件

import { NgModule }  from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { FormsModule } from '@angular/forms'; 
import { MyShopComponent } from './app.component'; 
@NgModule({ 
    imports: [ 
    BrowserModule, 
    FormsModule 
    ], 
    declarations: [ 
    MyShopComponent 
    ], 
    bootstrap: [ MyShopComponent ] 
}) 
export class AppModule { } 

回答

5

內部組件模板ngFor應該使用let來定義當前的可迭代變量。從*ngfor也是正確的錯字到*ngFor與包裝屬性由"

<p *ngFor="let movie of movieList">{{movie}}</p> 

Demo Plunkr

+0

它被添加,但得到 – balu

+0

哈其工作非常感謝 – balu

+0

給我從你身邊的任何建議學習角2 – balu