UI: Fixed error JIT Compilation and correct process
This commit is contained in:
parent
77567b8863
commit
843151ba44
@ -17,7 +17,6 @@
|
|||||||
import {
|
import {
|
||||||
Compiler,
|
Compiler,
|
||||||
Component,
|
Component,
|
||||||
ComponentFactory,
|
|
||||||
Injectable,
|
Injectable,
|
||||||
Injector,
|
Injector,
|
||||||
NgModule,
|
NgModule,
|
||||||
@ -26,9 +25,9 @@ import {
|
|||||||
Type,
|
Type,
|
||||||
ɵresetCompiledComponents
|
ɵresetCompiledComponents
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { from, Observable } from 'rxjs';
|
import { from, Observable, of } from 'rxjs';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { catchError, map, mergeMap } from 'rxjs/operators';
|
import { mergeMap } from 'rxjs/operators';
|
||||||
|
|
||||||
@NgModule()
|
@NgModule()
|
||||||
export abstract class DynamicComponentModule implements OnDestroy {
|
export abstract class DynamicComponentModule implements OnDestroy {
|
||||||
@ -79,33 +78,32 @@ export class DynamicComponentFactoryService {
|
|||||||
declarations: [comp],
|
declarations: [comp],
|
||||||
imports: moduleImports
|
imports: moduleImports
|
||||||
})(class DynamicComponentInstanceModule extends DynamicComponentModule {});
|
})(class DynamicComponentInstanceModule extends DynamicComponentModule {});
|
||||||
return from(this.compiler.compileModuleAsync(dynamicComponentInstanceModule)).pipe(
|
try {
|
||||||
map((module) => {
|
const module = this.compiler.compileModuleSync(dynamicComponentInstanceModule);
|
||||||
let moduleRef: NgModuleRef<any>;
|
let moduleRef: NgModuleRef<any>;
|
||||||
try {
|
try {
|
||||||
moduleRef = module.create(this.injector);
|
moduleRef = module.create(this.injector);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.compiler.clearCacheFor(module.moduleType);
|
this.compiler.clearCacheFor(module.moduleType);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
this.dynamicComponentModulesMap.set(comp, {
|
this.dynamicComponentModulesMap.set(comp, {
|
||||||
moduleRef,
|
moduleRef,
|
||||||
moduleType: module.moduleType
|
moduleType: module.moduleType
|
||||||
});
|
});
|
||||||
return {
|
return of( {
|
||||||
componentType: comp,
|
componentType: comp,
|
||||||
componentModuleRef: moduleRef
|
componentModuleRef: moduleRef
|
||||||
};
|
});
|
||||||
}),
|
} catch (error) {
|
||||||
catchError((error) => {
|
if (compileAttempt === 1) {
|
||||||
if (compileAttempt === 1) {
|
ɵresetCompiledComponents();
|
||||||
ɵresetCompiledComponents();
|
return this.createDynamicComponent(componentType, template, modules, preserveWhitespaces, ++compileAttempt, styles);
|
||||||
return this.createDynamicComponent(componentType, template, modules, preserveWhitespaces, ++compileAttempt, styles);
|
} else {
|
||||||
} else {
|
console.error(error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
);
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user