Angular 5 错误:无法绑定到“ngForFor”,因为它不是“li”的已知属性

Mus*_*SAL 0 javascript typescript angular

我的 category.component.ts 是 category.component.ts

import { Component, OnInit } from '@angular/core';
import { CategoryService } from './category.service';
import { Category } from './category';
@Component({
selector: 'app-category',
templateUrl: './category.component.html',
styleUrls: ['./category.component.css'],
providers: [CategoryService]
})
export class CategoryComponent implements OnInit {
title = 'Category';
categories: Category[];
constructor(private categoryService: CategoryService) {}
ngOnInit() {
this.getCategories();
}
getCategories() {
this.categoryService.getCategories().subscribe(res => {
  this.categories = res;
});
}
}
Run Code Online (Sandbox Code Playgroud)

我的 category.component.html 是 category.component.html

<h3>{{title}}</h3>
<ul>
<li *ngFor='let item2 for categories'>
  {{item2.CategoryName}}
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

我的 category.service.ts 是 category.service.ts

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Category } from './category';
 import { Observable } from 'rxjs';
@Injectable()
export class CategoryService {

constructor(private http: HttpClient) { }
getCategories(): Observable<Category[]> {
 return this.http.get<Category[]> 
 ('http://northwindapi.azurewebsites.net/api/categories');
 }
  }
Run Code Online (Sandbox Code Playgroud)

问题是 Angular 不接受 ngFor 的 li。我该如何解决这个问题?

Rez*_*eza 7

在表达式中更改forof

<li *ngFor='let item2 of categories'>
Run Code Online (Sandbox Code Playgroud)