【发布时间】:2017-12-19 18:11:24
【问题描述】:
大家好,我正在研究 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
我不明白为什么我要遵循不想使用复制粘贴的指南,因为我需要知道为什么会发生这种情况
【问题讨论】:
标签: angular components angular-ng-if