Skip to content

Need JitCompilerFactory in Angular 5 #20125

Closed

Description

@jackzard

I'm submitting a...


[ x] Feature request

Current behavior

no factory for JitCompilerFactory like Angular 4

Expected behavior

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

Activity

  1. changed the title [-]Need JitCompilerFactory[/-] [+]Need JitCompilerFactory in Angular 5[/+] on Nov 3, 2017
  2. p3x-robot commented on Nov 3, 2017

    @p3x-robot

    they are using it like this, this is bullshit:

    import { ɵa } from '@angular/platform-browser-dynamic';
  3. sarunint commented on Nov 3, 2017

    @sarunint
    Contributor

    Everything in @angular/compiler is not part of the public API and changes are subjected to happen.

  4. maxkoretskyi commented on Nov 3, 2017

    @maxkoretskyi

    I'd add that we need either JIT compiler that uses decorator or AOT compiler that uses static analysis, but in runtime

  5. trotyl commented on Nov 3, 2017

    @trotyl
    Contributor

    @MaximusK That's being discussed at #15510 & #15275, we don't need duplicate issue for tracking.

  6. maxkoretskyi commented on Nov 3, 2017

    @maxkoretskyi

    @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

  7. trotyl commented on Nov 3, 2017

    @trotyl
    Contributor

    @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.

  8. maxkoretskyi commented on Nov 3, 2017

    @maxkoretskyi

    @trotyl , just checked the sources:

    import {NowCardFeedNgFactory} from '../../ngfactory/src/demos/now-cards/now-card-feed.ngfactory'
    nge.define(NowCardFeedNgFactory);
    

    it imports pre-compiled factory. No runtime compilation. Can you maybe clarify what approach exactly from @angular/elements can be used?

  9. trotyl commented on Nov 3, 2017

    @trotyl
    Contributor

    @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.

  10. maxkoretskyi commented on Nov 3, 2017

    @maxkoretskyi

    @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.

  11. gkalpak commented on Nov 3, 2017

    @gkalpak
    Member

    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 😁)

  12. trotyl commented on Nov 3, 2017

    @trotyl
    Contributor

    Sorry for not make it clear, I'm just talking about using dynamic HTML with Angular components in runtime, not runtime AOT.

  13. maxkoretskyi commented on Nov 3, 2017

    @maxkoretskyi

    @gkalpak , @trotyl

    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.

  14. added
    area: core
    on Nov 3, 2017
  15. trotyl commented on Nov 3, 2017

    @trotyl
    Contributor

    @MaximusK I guess it's clear now, but still seems a duplication to me.

  16. 17 remaining items

  17. added a commit that references this issue on Nov 22, 2017
    d7a727c
  18. Sky4CE commented on Nov 27, 2017

    @Sky4CE

    After upgrading to Angular 5.1.0-beta.2 I still have error:
    image

  19. ocombe commented on Nov 27, 2017

    @ocombe
    Contributor

    You should not use it as a constructor, use the injector instead. See my comment here: #20639 (comment)

  20. VSmirnov17 commented on Nov 28, 2017

    @VSmirnov17

    I have 2 errors:
    selection_153
    selection_154

    Errors occur when I build project with --aot (ng serve --aot)
    If not --aot - all good

  21. ocombe commented on Nov 28, 2017

    @ocombe
    Contributor

    If you have a problem post the comments in the issue #20639, thanks.

  22. claygifford commented on Nov 28, 2017

    @claygifford

    ocombe your code does not work...

    core.js:1427 ERROR Error: StaticInjectorError[JitCompiler]:
    StaticInjectorError[JitCompiler]:
    NullInjectorError: No provider for JitCompiler!

  23. added a commit that references this issue on Dec 2, 2017
    cf0e3c6
  24. angular-automatic-lock-bot commented on Sep 12, 2019

    @angular-automatic-lock-bot

    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.

  25. locked and limited conversation to collaborators on Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: corefeature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions