feat(di): added context to runtime DI errors
This commit is contained in:
@ -419,6 +419,9 @@ export class ProtoElementInjector {
|
||||
getBindingAtIndex(index: number): any { return this.protoInjector.getBindingAtIndex(index); }
|
||||
}
|
||||
|
||||
class _Context {
|
||||
constructor(public element: any, public componentElement: any, public injector: any) {}
|
||||
}
|
||||
|
||||
export class ElementInjector extends TreeNode<ElementInjector> implements DependencyProvider {
|
||||
private _host: ElementInjector;
|
||||
@ -438,7 +441,9 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
|
||||
constructor(public _proto: ProtoElementInjector, parent: ElementInjector) {
|
||||
super(parent);
|
||||
|
||||
this._injector = new Injector(this._proto.protoInjector, null, this);
|
||||
this._injector =
|
||||
new Injector(this._proto.protoInjector, null, this, () => this._debugContext());
|
||||
|
||||
// we couple ourselves to the injector strategy to avoid polymoprhic calls
|
||||
var injectorStrategy = <any>this._injector.internalStrategy;
|
||||
this._strategy = injectorStrategy instanceof InjectorInlineStrategy ?
|
||||
@ -489,6 +494,12 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
|
||||
this.hydrated = true;
|
||||
}
|
||||
|
||||
private _debugContext(): any {
|
||||
var p = this._preBuiltObjects;
|
||||
return new _Context(p.elementRef.nativeElement, p.view.getHostElement().nativeElement,
|
||||
this._injector);
|
||||
}
|
||||
|
||||
private _reattachInjectors(imperativelyCreatedInjector: Injector): void {
|
||||
// Dynamically-loaded component in the template. Not a root ElementInjector.
|
||||
if (isPresent(this._parent)) {
|
||||
@ -613,7 +624,7 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
|
||||
return null;
|
||||
}
|
||||
|
||||
throw new NoBindingError(dirDep.key);
|
||||
throw new NoBindingError(null, dirDep.key);
|
||||
}
|
||||
return this._preBuiltObjects.templateRef;
|
||||
}
|
||||
|
@ -200,6 +200,11 @@ export class AppView implements ChangeDispatcher, RenderEventDispatcher {
|
||||
return isPresent(viewIndex) ? this.views[viewIndex] : null;
|
||||
}
|
||||
|
||||
getHostElement(): ElementRef {
|
||||
var boundElementIndex = this.mainMergeMapping.hostElementIndicesByViewIndex[this.viewOffset];
|
||||
return this.elementRefs[boundElementIndex];
|
||||
}
|
||||
|
||||
getDetectorFor(directive: DirectiveIndex): any {
|
||||
var childView = this.getNestedView(this.elementOffset + directive.elementIndex);
|
||||
return isPresent(childView) ? childView.changeDetector : null;
|
||||
|
Reference in New Issue
Block a user