没有RuntimeCompiler的运行时提供程序 [英] No runtime provider for RuntimeCompiler

查看:111
本文介绍了没有RuntimeCompiler的运行时提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循此处接受的答案,并调用RuntimeCompiler.clearCache()

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!

我在这里想念什么?

推荐答案

删除行

import { RuntimeCompiler } from '@angular/compiler';

然后添加编译器以导入@ angular/core.并将RuntimeCompiler替换为Compiler;

Then add Compiler to import @angular/core. And replace RuntimeCompiler to 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

这篇关于没有RuntimeCompiler的运行时提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆