Hi everyone i'm study angular2 now im workind with *ngIf and i have this code
<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>
And this is my 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=[];
}
My problem is when i run the web site i have this error:
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
I don't understand why i'm follow a guide in don't want use copy paste because i need know why is happen this
You need to remove the # in front of coursesList and noCourses. # is used only on the ng-template tag.
<div *ngIf='courses.length > 0 ; then coursesList else noCourses'>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With