fix(ivy): register to directive outputs on ng-template / ng-container (#25698)

Runtime part of #25697

PR Close #25698
This commit is contained in:
Pawel Kozlowski
2018-08-28 15:31:09 +02:00
committed by Misko Hevery
parent 3809e0fcae
commit 371df35624
3 changed files with 89 additions and 41 deletions

View File

@ -1202,7 +1202,6 @@ export function hostElement(
return node;
}
/**
* Adds an event listener to the current node.
*
@ -1215,29 +1214,35 @@ export function hostElement(
*/
export function listener(
eventName: string, listenerFn: (e?: any) => any, useCapture = false): void {
ngDevMode && assertPreviousIsParent();
ngDevMode && assertNodeOfPossibleTypes(previousOrParentNode, TNodeType.Element);
ngDevMode &&
assertNodeOfPossibleTypes(
previousOrParentNode, TNodeType.Element, TNodeType.Container, TNodeType.ElementContainer);
const node = previousOrParentNode;
const native = node.native as RElement;
ngDevMode && ngDevMode.rendererAddEventListener++;
// In order to match current behavior, native DOM event listeners must be added for all
// events (including outputs).
if (isProceduralRenderer(renderer)) {
const wrappedListener = wrapListenerWithDirtyLogic(viewData, listenerFn);
const cleanupFn = renderer.listen(native, eventName, wrappedListener);
storeCleanupFn(viewData, cleanupFn);
} else {
const wrappedListener = wrapListenerWithDirtyAndDefault(viewData, listenerFn);
native.addEventListener(eventName, wrappedListener, useCapture);
const cleanupInstances = getCleanup(viewData);
cleanupInstances.push(wrappedListener);
if (firstTemplatePass) {
getTViewCleanup(viewData).push(
eventName, node.tNode.index, cleanupInstances !.length - 1, useCapture);
// add native event listener - applicable to elements only
if (previousOrParentNode.tNode.type === TNodeType.Element) {
const native = node.native as RElement;
ngDevMode && ngDevMode.rendererAddEventListener++;
// In order to match current behavior, native DOM event listeners must be added for all
// events (including outputs).
if (isProceduralRenderer(renderer)) {
const wrappedListener = wrapListenerWithDirtyLogic(viewData, listenerFn);
const cleanupFn = renderer.listen(native, eventName, wrappedListener);
storeCleanupFn(viewData, cleanupFn);
} else {
const wrappedListener = wrapListenerWithDirtyAndDefault(viewData, listenerFn);
native.addEventListener(eventName, wrappedListener, useCapture);
const cleanupInstances = getCleanup(viewData);
cleanupInstances.push(wrappedListener);
if (firstTemplatePass) {
getTViewCleanup(viewData).push(
eventName, node.tNode.index, cleanupInstances !.length - 1, useCapture);
}
}
}
// subscribe to directive outputs
let tNode: TNode|null = node.tNode;
if (tNode.outputs === undefined) {
// if we create TNode here, inputs must be undefined so we know they still need to be