angular 2 ngIf 意外标记 #

angular 2 ngIf Unexpected token #

大家好,我正在研究 angular2,现在我在 *ngIf 工作,我有这个代码

<div *ngIf='courses.length > 0 ; then #coursesList else #noCourses'>
</div>
<ng-template #coursesList>
  <h1>List of courses</h1>
</ng-template>
<ng-template #noCourses>
  <h2>No courses yet</h2> 
</ng-template>

这是我的 component.ts

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

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
})
export class AppComponent {
    title = 'app hello';

    courses=[];
}

我的问题是当我 运行 网站出现此错误时:

Uncaught Error: Template parse errors:
Parser Error: Unexpected token # at column 27 in [courses.length > 0 ; then 
#coursesList else #noCourses] in ng:///AppModule/AppComponent.html@1:5 ("
<h1>Angular</h1>
<div [ERROR ->]*ngIf='courses.length > 0 ; then #coursesList else 
#noCourses'>
</div>
"): ng:///AppModule/AppComponent.html@1:5

我不明白为什么我要遵循不想使用复制粘贴的指南,因为我需要知道为什么会这样

您需要去掉coursesListnoCourses前面的#。 # 仅用于 ng-template 标签。

<div *ngIf='courses.length > 0 ; then coursesList else noCourses'>
</div>