gpt4 book ai didi

angular - JitCompilerFactory Angular 5

转载 作者:太空狗 更新时间:2023-10-29 17:51:41 25 4
gpt4 key购买 nike

如何在 Angular 5 中使用 JitCompilerFactory?

在 Angular 4 '@angular/compiler' 中导出 JitCompilerFactory

但在 Angular 5 文件中移动到“@angular/platform-b​​rowser-dynamic/src/compiler_factory”

这是我在 Angular 4 中的代码

import {CommonModule} from '@angular/common'
import {Compiler, NgModule} from '@angular/core'
import {JitCompilerFactory} from '@angular/compiler'
import {DynamicComponent} from './dynamic.component'
import {DynamicComponentModule} from './dynamic.module'

export function compilerFactory() {
return new JitCompilerFactory([{useDebug: false, useJit: true}]).createCompiler()
}

@NgModule({
imports: [
CommonModule,
],
declarations: [
DynamicComponent
],
exports: [
DynamicComponent
],
providers: [
DynamicComponentModule,
{provide: Compiler, useFactory: compilerFactory}
],
})
export class DynamicModule {
}

如何让它在 Angular 5 中工作?

最佳答案

您必须将 @angular/platform-b​​rowser-dynamic 更新到最新版本 (5.1.0-beta.2) 并从以下位置获取工厂:

@angular/platform-browser-dynamic

The third beta brings 10 bugfixes and one feature, namely: platform-browser-dynamic: export JitCompilerFactory (#20478) (d7a727c), closes #20125

那么,你不应该自己创建编译器,你需要让注入(inject)器在这里完成工作:

import {Compiler, COMPILER_OPTIONS, CompilerFactory, NgModule} from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import {JitCompilerFactory} from '@angular/platform-browser-dynamic';

import { AppComponent } from './app.component';

export function createCompiler(compilerFactory: CompilerFactory) {
return compilerFactory.createCompiler();
}

@NgModule({
imports: [BrowserModule],
bootstrap: [AppComponent],
declarations: [AppComponent],
providers: [
{provide: COMPILER_OPTIONS, useValue: {}, multi: true},
{provide: CompilerFactory, useClass: JitCompilerFactory, deps: [COMPILER_OPTIONS]},
{provide: Compiler, useFactory: createCompiler, deps: [CompilerFactory]}
]
})
export class AppModule {}

很抱歉告诉你,但显然这还行不通,因为工作仍在进行中:

归功于那些人:https://github.com/angular/angular/issues/20639#issuecomment-347149868

它扼杀了我的周末,所以我希望它能有所帮助 :) 干杯!

关于angular - JitCompilerFactory Angular 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47080671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com