2016-11-14 53 views
1

我已搜索此herehere。我使用的2.0.0-beta.7版2角,但它給我的錯誤是這樣的:EXCEPTION:模板解析錯誤:無法綁定到'ngForFrom',因爲它不是已知的本地屬性

EXCEPTION: Template parse errors: 
Can't bind to 'ngForFrom' since it isn't a known native property ("<h2>list of fruits</h2> 

<ul> 
<li [ERROR ->]*ngFor="#item from itemList">{{item.name}}</li> 
</ul>"): [email protected]:4 
Property binding ngForFrom not used by any directive on an embedded template ("<h2>list of fruits</h2> 
<ul> 
按照

知道它是用駱駝外殼,但它不是爲我工作。

這裏是我的.ts文件:

import {Component} from "angular2/core"; 

@Component({ 
selector:'my-list' 
template:`<h2>list of fruits</h2> 
<ul> 
<li *ngFor="#item from itemList">{{item.name}}</li> 
</ul>` 
}) 

export class ItemComponent{ 
public itemList=[ 
{name:"Apple"}, 
{name:"Orange"}, 
{name:"Grapes"} 
]; 

} 
+2

將itemite項目中的#item改爲itemList項目的#item。 – yurzui

+1

嘗試使用'* ngFor =「let itemList」'。 –

+1

@Lenilson de Castro似乎他使用的是舊版本,所以'let'不會工作 – yurzui

回答

2

請使用角2發佈的最新版本,並如下修改代碼。

相比,你的代碼
import { Component } from "@angular/core"; 

@Component({ 
    selector: 'my-list', 
    template: `<h2>list of fruits</h2> 
       <ul> 
        <li *ngFor="let item of itemList">{{item.name}}</li> 
       </ul>` 
}) 

export class ItemComponent { 
    public itemList = [ 
     { name: "Apple" }, 
     { name: "Orange" }, 
     { name: "Grapes" } 
    ]; 

} 

的主要變化:

import {Component} from "angular2/core"; 

import { Component } from "@angular/core"; 

而且

<li *ngFor="#item from itemList">{{item.name}}</li> 

<li *ngFor="let item of itemList">{{item.name}}</li> 
相關問題