2017-07-14 26 views
3

こんにちは誰も私は、研究angular2 *ngIfと今イムworkindをしていると私は、このコード角度2 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/[email protected]:5 (" 
<h1>Angular</h1> 
<div [ERROR ->]*ngIf='courses.length > 0 ; then #coursesList else 
#noCourses'> 
</div> 
"): ng:///AppModule/[email protected]:5 

なぜ私は理解していません私はなぜコピーペーストを使用したくないのか知る必要があるので、このガイドを参考にしてください。

答えて

3

coursesListnoCoursesの前に#を付ける必要があります。 #はng-templateタグでのみ使用されます。

<div *ngIf='courses.length > 0 ; then coursesList else noCourses'> 
</div> 
関連する問題