Hi I've been trying to learn Angular in the past days and I would like to use ngHtmlBind or ngInclude directives. However, when I use it and serve my app, the console says this:
Uncaught Error: Template parse errors:
Can't bind to 'ngBindHtml' since it isn't a known property of 'div'.Uncaught Error: Template parse errors:
Can't bind to 'ngInclude' since it isn't a known property of 'div'.
I am at a loss reading the documentation. Maybe it's because I am using the CLI and directives are called differently (i.e. instead of 'ng-for', it is implemented as *ngFor)?
I tried ngFor and ngIf and they are working correctly. But when I use ngBindHtml and ngInclude, the error shows up.
Here is my code:
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { SonglistComponent } from './songlist/songlist.component';
import { ChartComponent } from './chart/chart.component';
import { DataService } from './data.service';
import { SafePipe } from './safe.pipe';
@NgModule({
declarations: [
AppComponent,
SonglistComponent,
ChartComponent,
SafePipe
],
imports: [
BrowserModule
],
providers: [DataService],
bootstrap: [AppComponent]
})
export class AppModule { }
chart.component.html
<div class="chart" *ngFor="let song of dataService.currentPlaylist">
<div class="chart-options">
<span class="glyphicon glyphicon-remove" aria-hidden="true" (click)="closeChart()"></span>
</div>
<h1 class="chart-title">{{song.title}}</h1>
<p class="chart-artist">by {{song.artist}}</p>
<p class="chart-key">Key: {{song.key}}</p>
<div class="chart-body" *ngBindHtml="song.chart">
</div>
</div>