简体   繁体   中英

Angular2 No provider for CompileMetadataResolver

So I've upgrade from RC1 to the final release of Angular2. I've done a lot of adjustments but every time I injected RuntimeCompiler on my AppComponent , this error occurs.

没有CompileMetadataResolver的提供程序

I have no idea what is happening here and haven't seen the answers for the web regarding this issue. Any help would be appreciated, anyway here is my AppComponent for reference.

import { Component } from '@angular/core';
import { Location } from '@angular/common';
import { Router } from '@angular/router';
import { RuntimeCompiler } from '@angular/compiler';

@Component({
    selector: 'content',
    template: '<router-outlet></router-outlet>'
})
export class AppComponent {
    constructor(
        private location: Location,
        private router: Router,
        private runtimeCompiler: RuntimeCompiler
    ) {;

        if (localStorage.getItem('id_token') == undefined) {
            if (location.path().toLowerCase().startsWith('/login')) {
                // LET IT BE
            } else {
                router.navigate(['login']);
            }

            runtimeCompiler.clearCache();
        } else {
            router.navigate(['menu']);
        }
    }
}

Thank you in advance.

I would say, that you should add the providers set to the app module:

import { COMPILER_PROVIDERS } from "@angular/compiler";
...

@NgModule({
    imports: [
        ...
        BrowserModule
    ],
    declarations: [ ... ],
    bootstrap:    [ ... ],
    providers: [
        COMPILER_PROVIDERS
    ],
})
export class AppModule { }

This set COMPILER_PROVIDERS of providers contains all what is needed by RuntimeCompiler . There is an example with working plunker using that piece of code How can I use/create dynamic template to compile dynamic Component with Angular 2.0? and some more details...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM