You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
export JitCompilerFactory in Angular 5 or alternative
Example code in 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 {
}
Environment
Angular version: 5.0.0
For Tooling issues:
- Node version: 8.4.0
- Platform: Windows
Reacted by jaa1982, Aluan Haddad, Torqode, Pavel Hrabec, Max Koretskyi, patrikx3, jerry7411, Mario Nguyen, Jimmy Wijaya, Dede Adhyatmika_099279 and 15 more
Reacted by Trotyl Yu, Fabian Wiles and Reactive Fox
@trotyl , I didn't create the issue. So do you know what Angular team plans to do with the compiler? I saw a doc once that stated that there were plans to move to AOT runtime
@MaximusK AFAIK there's no plan for runtime AOT (if you mean AOT editor, that's already in progress at edit.ng), but most of it solves could be covered by @angular/elements, which is based on the dynamic template solution used in angular.io.
@MaximusK Angular Elements will wrap your Angular component into a web component, possibility you can have a look of the introduction in Angular MIX, which can demonstrate it clearly.
@trotyl, thanks, I've watched the talk and get the idea behind the @angular/elements, however, I haven't found anything related to the runtime compilation in the sources. As I understand it's still a concept that's why it imports compiled factory instead of compiling the component.
I think there is some confusion here. Neither angular.io nor @angular/elements deal with aot-vs-jit compilation. (Both can work with either and prefer aot for the known reasons 😁)
Let's clarify what we're talking about here. You can have a string like this:
@Component({
template: `<span>generated on the fly: {{name}}</span>`
});
class MyComp {}
and we want to generate compiled component factory (mycom.ngfactory) to work with dynamic components as explained in this article.
This factory can be generated by Angular View Compiler which takes component metadata (template etc) as an input. This metadata can be obtained using either JIT or AOT compiler. JIT compiler requires evaluation of the code so that Component decorator gets executed and attaches metadata to a class which is then retrieved by JIT compiler. AOT compiler doesn't need evaluation and works with AST produced by TypeScript (through transforms as I understand in the v5). So when I said:
I'd add that we need either JIT compiler that uses decorator or AOT compiler that uses static analysis, but in runtime, not build time
I meant that we need any of the two to be able to produce factory in runtime (not build time) on demand if the component template is unknown during build.
Activity
[-]Need JitCompilerFactory[/-][+]Need JitCompilerFactory in Angular 5[/+]p3x-robot commentedon Nov 3, 2017
they are using it like this, this is bullshit:
sarunint commentedon Nov 3, 2017
Everything in
@angular/compileris not part of the public API and changes are subjected to happen.maxkoretskyi commentedon Nov 3, 2017
I'd add that we need either JIT compiler that uses decorator or AOT compiler that uses static analysis, but in runtime
trotyl commentedon Nov 3, 2017
@MaximusK That's being discussed at #15510 & #15275, we don't need duplicate issue for tracking.
maxkoretskyi commentedon Nov 3, 2017
@trotyl , I didn't create the issue. So do you know what Angular team plans to do with the compiler? I saw a doc once that stated that there were plans to move to AOT runtime
trotyl commentedon Nov 3, 2017
@MaximusK AFAIK there's no plan for runtime AOT (if you mean AOT editor, that's already in progress at edit.ng), but most of it solves could be covered by
@angular/elements, which is based on the dynamic template solution used in angular.io.maxkoretskyi commentedon Nov 3, 2017
@trotyl , just checked the sources:
it imports pre-compiled factory. No runtime compilation. Can you maybe clarify what approach exactly from
@angular/elementscan be used?trotyl commentedon Nov 3, 2017
@MaximusK Angular Elements will wrap your Angular component into a web component, possibility you can have a look of the introduction in Angular MIX, which can demonstrate it clearly.
maxkoretskyi commentedon Nov 3, 2017
@trotyl, thanks, I've watched the talk and get the idea behind the
@angular/elements, however, I haven't found anything related to the runtime compilation in the sources. As I understand it's still a concept that's why it imports compiled factory instead of compiling the component.gkalpak commentedon Nov 3, 2017
I think there is some confusion here. Neither angular.io nor
@angular/elementsdeal with aot-vs-jit compilation. (Both can work with either and prefer aot for the known reasons 😁)trotyl commentedon Nov 3, 2017
Sorry for not make it clear, I'm just talking about using dynamic HTML with Angular components in runtime, not runtime AOT.
maxkoretskyi commentedon Nov 3, 2017
@gkalpak , @trotyl
Let's clarify what we're talking about here. You can have a string like this:
and we want to generate compiled component factory (
mycom.ngfactory) to work with dynamic components as explained in this article.This factory can be generated by Angular View Compiler which takes component metadata (template etc) as an input. This metadata can be obtained using either JIT or AOT compiler. JIT compiler requires evaluation of the code so that
Componentdecorator gets executed and attaches metadata to a class which is then retrieved by JIT compiler. AOT compiler doesn't need evaluation and works with AST produced by TypeScript (through transforms as I understand in the v5). So when I said:I meant that we need any of the two to be able to produce factory in runtime (not build time) on demand if the component template is unknown during build.
trotyl commentedon Nov 3, 2017
@MaximusK I guess it's clear now, but still seems a duplication to me.
17 remaining items
feat(platform-browser-dynamic): export `JitCompilerFactory` (#20478)
Sky4CE commentedon Nov 27, 2017
After upgrading to Angular 5.1.0-beta.2 I still have error:

ocombe commentedon Nov 27, 2017
You should not use it as a constructor, use the injector instead. See my comment here: #20639 (comment)
VSmirnov17 commentedon Nov 28, 2017
I have 2 errors:


Errors occur when I build project with --aot (ng serve --aot)
If not --aot - all good
ocombe commentedon Nov 28, 2017
If you have a problem post the comments in the issue #20639, thanks.
claygifford commentedon Nov 28, 2017
ocombe your code does not work...
core.js:1427 ERROR Error: StaticInjectorError[JitCompiler]:
StaticInjectorError[JitCompiler]:
NullInjectorError: No provider for JitCompiler!
feat(platform-browser-dynamic): export `JitCompilerFactory` (angular#…
angular-automatic-lock-bot commentedon Sep 12, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.