3

Angular 2 文档似乎是正确的。在 app.html 中使用 *ngFor="let hero of heros" 调用时,我的位于 app.component.ts 中的字符串数组似乎无法识别

非常感谢您尝试通过教程运行所有帮助!

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 = '';
  }
}

应用程序.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>
4

1 回答 1

-1

你可以这样使用:

英雄 : String[]= ['Windstorm', 'Bombasto', 'Magneta', 'Tornado'];

于 2018-08-24T08:59:25.477 回答