0

I have this in my app/component.ts

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

@Component({
  selector: 'app-root',
  template: `
    <ul>
      <li *ngFor="let course of courses">
        {{ course }}
      </li>
    </ul>
  `,
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  course = ['Course 1', 'Course 2', 'Course 3'];
}

And in my app.module.ts, I also imported the necessary things

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    CommonModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

This is just a simple *ngFor code but why is it not working. Aside from these, I have not touched anything

4

1 回答 1

4

你有一个错字,检查你的组件定义。您定义course = [...];但您courses在模板中使用。尝试将组件中的变量名称更改为课程

于 2017-06-13T08:08:04.510 回答