Angular 2文档似乎是正确的。使用* ngFor =“英雄英雄”在app.html中调用时,似乎无法识别位于app.component.ts中的我的String数组
只是试着通过一个教程,非常感谢所有的帮助!
app.component.ts
import {
Component,
Attribute
} from 'angular2/core';
import {FORM_DIRECTIVES, CORE_DIRECTIVES} from 'angular2/common'
@Component({
selector: 'my-app',
templateUrl: 'app/app.html',
directives: [FORM_DIRECTIVES, CORE_DIRECTIVES]
})
export class AppComponent {
private newSearchTerm: string;
private channels: String[];
heroes = ['Windstorm', 'Bombasto', 'Magneta', 'Tornado'];
constructor() {
this.channels = [];
}
public newSubscription() {
this.channels.push(this.newSearchTerm);
this.newSearchTerm = '';
}
}
app.html
<div id="app">
<div id="search-form">
<form (ngSubmit)="newSubscription()">
<input [(ngModel)]="newSearchTerm" placeholder="JavaScript" />
<button>Search</button>
</form>
</div>
<ul id="channels-list">
<li *ngFor="let hero of heroes">
{{ hero }}
</li>
</ul>
</div>
答案 0 :(得分:-1)
您可以这样使用:
heroes:String [] = ['Windstorm','Bombasto','Magneta','Tornado'];