I'm trying to follow the accepted answer here, and make a call to RuntimeCompiler.clearCache()
Here's how I've tried to do it:
import { Component } from '@angular/core';
import { OnInit } from '@angular/core';
import { RuntimeCompiler } from '@angular/compiler';
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: 'app.component.html',
})
export class AppComponent implements OnInit {
constructor(private _runtimeCompiler: RuntimeCompiler) {}
ngOnInit() {
this._runtimeCompiler.clearCache();
}
}
But I'm getting this error:
ORIGINAL EXCEPTION: No provider for RuntimeCompiler!
What am I missing to here?
Add RuntimeCompiler as provider in your
component
.With RC5+ this providers should be registered on a AppModule level
Check this How can I use/create dynamic template to compile dynamic Component with Angular 2.0? for a working plunker
Add
RuntimeCompiler
to your component providers. (providers: [RuntimeCompiler]
, belowtemplateUrl
)Remove the line
Then add Compiler to import @angular/core. And replace RuntimeCompiler to Compiler;
https://angular.io/docs/ts/latest/api/core/index/Compiler-class.html