[英]Can't bind to 'ngFor' since it isn't a known property of ... on hybrid AngularJS & Angular application
[英]|Official guide broken?| Can't bind to 'ngFor' since it isn't a known native property
我使用的是截至目前的最新版本的Angular2,並遵循Angular 2網站上的官方示例。 https://angular.io/docs/ts/latest/tutorial/toh-pt2.html
我正在嘗試使用*ngFor
解析數組,並獲得以下異常Template parse errors: Can't bind to 'ngFor' since it isn't a known native property
。
我看過另一篇有關語法的文章,但據我所知語法沒有錯。
有人可以告訴我我要去哪里錯了。 謝謝!!!
import {Component} from 'angular2/core';
export class Hero {
id:number;
name:string;
}
@Component({
selector: 'my-app',
template: `
<h1>{{title}}</h1>
<h2>My Heroes</h2>
<ul class="heroes">
<li *ngFor="let hero of heroes">
</li>
</ul>
<h2>{{hero.name}} details</h2>
<div><label>id: </label>
{{hero.id}}</div>
<div><label>name: </label>
<input [(ngModel)] = "hero.name"
placeholder="Hero Name">
</div>
`,
})
export class AppComponent {
title = 'Quest of Heroes'
hero:Hero = {id: 1, name: 'Windstorm'};
public heroes = HEROES;
}
const HEROES:Hero[] = [
{id: 11, name: 'Mr. Nice'},
{id: 12, name: 'Narco'},
{id: 13, name: 'bombboy'},
{id: 14, name: 'Dr. Deseract'},
{id: 15, name: 'Miss. Mistique'},
{id: 16, name: 'codeopolos'},
{id: 17, name: 'jupitarious'}
];
///<reference path="../node_modules/angular2/typings/browser.d.ts"/>
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from "./app.component";
bootstrap(AppComponent);
發生此錯誤是因為您使用了不推薦使用的angular 2版本。 我可以通過導入角度模塊的方式來說明這一點。
在較新的版本上,不再需要導入ngFor或ngIf。
最重要的是,沒有理由在發布候選版本之前使用任何版本來構建任何東西。
您必須從庫中import
ngFor
import {FORM_DIRECTIVES, NgFor, NgIf} from '@angular/common';
感謝您的見解,我在Angular上運行了舊版本。 現在工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.