fix(ivy): throw meaningful error for uninitialized output (#28085)

Throws a similar error to ViewEngine when encountering an `@Output` that hasn't been initialized to an `Observable`.

These changes resolve FW-680.

PR Close #28085
This commit is contained in:
crisbeto
2019-01-11 21:14:42 +01:00
committed by Andrew Kushnir
parent 693045165c
commit da8ee29e72
2 changed files with 21 additions and 15 deletions

View File

@ -14,6 +14,7 @@ import {validateAttribute, validateProperty} from '../sanitization/sanitization'
import {Sanitizer} from '../sanitization/security';
import {StyleSanitizeFn} from '../sanitization/style_sanitizer';
import {assertDataInRange, assertDefined, assertEqual, assertLessThan, assertNotEqual} from '../util/assert';
import {isObservable} from '../util/lang';
import {normalizeDebugBindingName, normalizeDebugBindingValue} from '../util/ng_reflect';
import {assertHasParent, assertPreviousIsParent} from './assert';
@ -936,7 +937,14 @@ export function listener(
const declaredName = props[i++] as string;
ngDevMode && assertDataInRange(lView, directiveIndex as number);
const directive = unwrapOnChangesDirectiveWrapper(lView[directiveIndex]);
const subscription = directive[minifiedName].subscribe(listenerFn);
const output = directive[minifiedName];
if (ngDevMode && !isObservable(output)) {
throw new Error(
`@Output ${minifiedName} not initialized in '${directive.constructor.name}'.`);
}
const subscription = output.subscribe(listenerFn);
const idx = lCleanup.length;
lCleanup.push(listenerFn, subscription);
tCleanup && tCleanup.push(eventName, tNode.index, idx, -(idx + 1));