-
Notifications
You must be signed in to change notification settings - Fork 12k
fail to build with (COMPILER_PROVIDERS (@angular/compiler)) as a provider #3619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As of beta.22, the CLI requires your app to be statically analyzable even in JIT mode. |
@clydin that's a bug; not a new feature... |
@rolandoldengarm that is by design actually. |
Could someone please drop a line or two on how to reference COMPILER_PROVIDERS in the 'providers' sections of an NgModule correctly? It resides in @angular/compiler just like the JitCompiler class. |
@SebastianFree if you need to dynamically create instances of components you can do something like the following. Keep in mind that any components you want to dynamically create need to be in the entryComponents list in the NgModule. For Future reference quests like this are probably best for Stack Overflow. (especially since this issue is closed) import { Injectable, ComponentRef, ComponentFactoryResolver, Injector } from '@angular/core';
@Injectable()
export class ComponentCreatorService {
constructor(private resolver: ComponentFactoryResolver, private injector: Injector) { }
createComponent<T>(ComponentClass: any): ComponentRef<T> {
// the component factory resolver is used to create a component factory
const factory = this.resolver.resolveComponentFactory(ComponentClass);
// factory.create() accepts a single argument which is an Injector reference
const component: ComponentRef<any> = factory.create(this.injector);
return component;
}
} |
I meant that it's a bug that Angular CLI always builds in AOT mode. I hope that that is not by design? |
It doesn't. Both JIT and AOT mode require statically analyzable code which is why it may look like it does. |
Hi, thanks for replying. There is in fact a question regarding this topic on StackOverflow. It didn't have an answer until now, when I found the good workaround, or actually it does seem to be a proper solution. There is the 'JitCompilerFactory' in '@angular/compiler'. When using this factory, you can leave out COMPILER_PROVIDERS and JitCompiler from the 'providers' section of the module, and use the factory directly. I included this answer in the SO link, as well as here for others to not have the same problem. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
OS
Microsoft Windows [Version 10.0.14393]
Versions
angular-cli: 1.0.0-beta.22-1
node: 6.6.0
os: win32 x64
Repro steps
The log given by the failure.
Mention any other details that might be useful.
you can get around the problem by commenting "providers: [COMPILER PROVIDERS],".
save and run ng server and then uncomment the line. this complis but the problem recurs if you restart ng server.
The text was updated successfully, but these errors were encountered: