我试图按照接受的答案,并调用RuntimeCompiler.clearCache()
以下是我尝试过的方法:
sed -E "/^compile 'com.test/ s/[^:]+$/+'/" moo.txt
但是我收到了这个错误:
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();
}
}
我在这里错过了什么?
答案 0 :(得分:2)
使用RC5 +,此提供者应在AppModule级别注册
@NgModule({
imports: [
BrowserModule
...
],
declarations: [ ... ],
bootstrap: [ ... ],
providers: [
COMPILER_PROVIDERS
],
})
export class AppModule { }
检查此How can I use/create dynamic template to compile dynamic Component with Angular 2.0?是否有工作的傻瓜
答案 1 :(得分:2)
删除行
import { RuntimeCompiler } from '@angular/compiler';
然后添加Compiler以导入@ angular / core。并将RuntimeCompiler替换为Compiler;
import { Component, Compiler } from '@angular/core';
import { OnInit } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: 'app.component.html',
})
export class AppComponent implements OnInit {
constructor(private _compiler: Compiler) {}
ngOnInit() {
this._compiler.clearCache();
}
}
https://angular.io/docs/ts/latest/api/core/index/Compiler-class.html
答案 2 :(得分:1)
将RuntimeCompiler
添加到您的组件提供商。 (providers: [RuntimeCompiler]
,低于templateUrl
)
答案 3 :(得分:1)
在component
。
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',
providers: [RuntimeCompiler]
})
export class AppComponent implements OnInit {
constructor(private _runtimeCompiler: RuntimeCompiler) {}
ngOnInit() {
this._runtimeCompiler.clearCache();
}
}