2

I have a random markups from back-end that should be compiled in runtime with JiT. Every component used in this markups is already pre-compiled with AoT (added to entryComponents block) and so has component factory in runtime. When JiT compiles provided markup it ignores existing components factories and re-compile every inner component.
Is there any way to provide component's AoT pre-compiled factories to JiT compilator to compile only one dynamic component with dynamic template?

Markup that should be compilated looks like this

<exercise1 smth="smth">
  <exercise1-answer>smth</exercise1-answer>
</exercise1>
<some-wrapper-cmp>
  <exercise2 smth="smth">
    <exercise2-answer>smth</exercise2-answer>
  </exercise2>
</some-wrapper-cmp>

with arbitrary nesting (regular markup can contains 1500-2000 DOM nodes)

p.s. i'm using this way to get JiT with AoT https://github.com/angular/angular/issues/15510#issuecomment-294301758 and then just

const component = Component({ template })(class {});
const module = NgModule({ imports, declarations: [ component ], schemas })(class {});

this.compiler.compileModuleAndAllComponentsAsync(module)
  .then(factories => factories.componentFactories.filter(factory => factory.componentType === component)[0])
  .then(componentFactory => {
    this.componentRef = this.viewContainerRef.createComponent(
      componentFactory,
      null,
      this.viewContainerRef.injector
    );

    this.compilationEnd.emit();
  });`enter code here`
skink
  • 5,133
  • 6
  • 37
  • 58
drow
  • 194
  • 3
  • 15
  • 1
    Please add more specifix example. Maybe you can create github repository with your problem – yurzui Oct 24 '17 at 14:07
  • what example do you mean? I've added a makrup example and comment about it. – drow Oct 24 '17 at 16:59
  • Which components from markup have already precompiled factories? Which components are you adding to dynamic module? It would be better to understand if you provided a minimal reproduction – yurzui Oct 24 '17 at 17:20
  • Every component from markup is precompiled, i only need to compile in runtime this template via dynamically created component (it's the one who should be compiled via JiT) – drow Oct 24 '17 at 17:34
  • @drow Did you ever resolve your issue. I'm running into the same thing. Consuming AOT compiled components from dynamic JIT compiled components. – adamclerk Nov 08 '17 at 15:11
  • @adamclerk nope, we moved to manually instantiating each component on inserted in DOM markup via `componentFactory.create` also there is some answer here but i did not try it https://github.com/angular/angular/issues/19901 – drow Nov 09 '17 at 16:08

0 Answers0