fix(ivy): not throwing error for unknown properties on container nodes (#29691)

Fixes Ivy not throwing an error if it runs into an invalid property binding on a container node (e.g. `<div *ngFor="let row of rows">` instead of `<div *ngFor="let row if rows">`).

This PR resolves FW-1219.

PR Close #29691
This commit is contained in:
Kristiyan Kostadinov
2019-04-08 19:59:39 +02:00
committed by Igor Minar
parent 66b87cef33
commit d144a3bd91
2 changed files with 34 additions and 2 deletions

View File

@ -161,6 +161,12 @@ function elementPropertyInternal<T>(
(element as RElement).setProperty ? (element as any).setProperty(propName, value) :
(element as any)[propName] = value;
}
} else if (tNode.type === TNodeType.Container) {
// If the node is a container and the property didn't
// match any of the inputs or schemas we should throw.
if (ngDevMode && !matchingSchemas(lView, tNode.tagName)) {
throw createUnknownPropertyError(propName, tNode);
}
}
}
@ -209,8 +215,7 @@ function validateAgainstUnknownProperties(
// and isn't a synthetic animation property...
propName[0] !== ANIMATION_PROP_PREFIX) {
// ... it is probably a user error and we should throw.
throw new Error(
`Template error: Can't bind to '${propName}' since it isn't a known property of '${tNode.tagName}'.`);
throw createUnknownPropertyError(propName, tNode);
}
}
@ -257,3 +262,13 @@ function savePropertyDebugData(
}
}
}
/**
* Creates an error that should be thrown when encountering an unknown property on an element.
* @param propName Name of the invalid property.
* @param tNode Node on which we encountered the error.
*/
function createUnknownPropertyError(propName: string, tNode: TNode): Error {
return new Error(
`Template error: Can't bind to '${propName}' since it isn't a known property of '${tNode.tagName}'.`);
}