MCPcopy Create free account
hub / github.com/angular/angular / validateNoEventBindings

Function validateNoEventBindings

packages/compiler/src/render3/view/compiler.ts:605–626  ·  view source on GitHub ↗

* Validates that there are no event attribute bindings in the host bindings. * @param bindings - Map of host bindings for the component. * @param bindingParser - Binding parser used to create the binding expression. * @param sourceSpan - Source span where the host bindings were defined.

(
  bindings: ParsedHostBindings,
  bindingParser: BindingParser,
  sourceSpan: ParseSourceSpan,
)

Source from the content-addressed store, hash-verified

603 * @param sourceSpan - Source span where the host bindings were defined.
604 */
605function validateNoEventBindings(
606 bindings: ParsedHostBindings,
607 bindingParser: BindingParser,
608 sourceSpan: ParseSourceSpan,
609): void {
610 for (const prop in bindings.properties) {
611 const isAttr = prop.startsWith('attr.');
612 const boundName = isAttr ? prop.slice(5) : prop;
613
614 if (boundName.toLowerCase().startsWith('on')) {
615 const errorType = isAttr ? 'attribute' : 'property';
616 const suggestion = `(${boundName.slice(2)})=...`;
617
618 let msg = `Binding to event ${errorType} '${boundName}' is disallowed for security reasons, please use ${suggestion}`;
619 if (!isAttr) {
620 msg += `\nIf '${prop}' is a directive input, make sure the directive is imported by the current module.`;
621 }
622
623 bindingParser.errors.push(new ParseError(sourceSpan, msg));
624 }
625 }
626}
627
628function compileStyles(styles: string[], selector: string, hostSelector: string): string[] {
629 const shadowCss = new ShadowCss();

Callers 1

verifyHostBindingsFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected