fix: element injector vs module injector (#15044)
fixes #12869 fixes #12889 fixes #13885 fixes #13870 Before this change there was a single injector tree. Now we have 2 injector trees, one for the modules and one for the components. This fixes lazy loading modules. See the design docs for details: https://docs.google.com/document/d/1OEUIwc-s69l1o97K0wBd_-Lth5BBxir1KuCRWklTlI4 BREAKING CHANGES `ComponentFactory.create()` takes an extra optional `NgModuleRef` parameter. No change should be required in user code as the correct module will be used when none is provided DEPRECATIONS The following methods were used internally and are no more required: - `RouterOutlet.locationFactoryResolver` - `RouterOutlet.locationInjector`
This commit is contained in:

committed by
Chuck Jazdzewski

parent
f093501501
commit
13686bb518
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {NgIf} from '@angular/common';
|
||||
import {ComponentFactory, ComponentRef, Injector, RendererFactory2, RootRenderer, Sanitizer, TemplateRef, ViewContainerRef} from '@angular/core';
|
||||
import {ComponentFactory, ComponentFactoryResolver, ComponentRef, Injector, NgModuleRef, RendererFactory2, RootRenderer, Sanitizer, TemplateRef, ViewContainerRef} from '@angular/core';
|
||||
import {ArgumentType, BindingType, NodeFlags, ViewDefinition, ViewFlags, anchorDef, createComponentFactory, directiveDef, elementDef, initServicesIfNeeded, textDef, viewDef} from '@angular/core/src/view/index';
|
||||
import {DomRendererFactory2} from '@angular/platform-browser/src/dom/dom_renderer';
|
||||
import {DomSanitizerImpl, SafeStyle} from '@angular/platform-browser/src/security/dom_sanitization_service';
|
||||
@ -84,7 +84,7 @@ function TreeComponent_0(): ViewDefinition {
|
||||
});
|
||||
}
|
||||
|
||||
export class AppModule implements Injector {
|
||||
export class AppModule implements Injector, NgModuleRef<any> {
|
||||
private sanitizer: DomSanitizerImpl;
|
||||
private componentFactory: ComponentFactory<TreeComponent>;
|
||||
private renderer2: RendererFactory2;
|
||||
@ -108,12 +108,22 @@ export class AppModule implements Injector {
|
||||
return this.sanitizer;
|
||||
case RootRenderer:
|
||||
return null;
|
||||
case NgModuleRef:
|
||||
return this;
|
||||
}
|
||||
return Injector.NULL.get(token, notFoundValue);
|
||||
}
|
||||
|
||||
bootstrap() {
|
||||
this.componentRef = this.componentFactory.create(this, [], this.componentFactory.selector);
|
||||
this.componentRef =
|
||||
this.componentFactory.create(Injector.NULL, [], this.componentFactory.selector, this);
|
||||
}
|
||||
|
||||
tick() { this.componentRef.changeDetectorRef.detectChanges(); }
|
||||
|
||||
get injector() { return this; }
|
||||
get componentFactoryResolver(): ComponentFactoryResolver { return null; }
|
||||
get instance() { return this; }
|
||||
destroy() {}
|
||||
onDestroy(callback: () => void) {}
|
||||
}
|
||||
|
Reference in New Issue
Block a user