【问题标题】:need solution with ngfor需要 ngfor 的解决方案
【发布时间】:2017-10-02 03:33:45
【问题描述】:
//appcomponent.ts
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  heroes=[{name:"superman"},{name:"heman"}];
}
//app.component.html

<ul><li *ngfor="let hero of heroes">{{hero.name}}</li></ul>

此代码不起作用,并给我空白输出。如果您对此有解决方案。请告诉我

【问题讨论】:

  • *ngFor 而不是 *ngfor?
  • *ngFor 不是 *ngfor
  • 谢谢 picci ...

标签: angular angular2-template angular2-forms


【解决方案1】:

你在*ngfor 上犯了一个小语法错误 它遵循驼峰式大小写,其中 f 必须大写。

下面附上正确的代码:

<ul>
  <li *ngFor="let hero of heroes">
    {{hero.name}}
  </li>
</ul>

【讨论】:

    猜你喜欢
    • 2016-03-31
    • 1970-01-01
    • 1970-01-01
    • 2023-01-26
    • 2015-06-04
    • 1970-01-01
    • 2021-12-19
    • 2023-02-13
    • 2019-11-17
    相关资源
    最近更新 更多