Skip to content

Feature Request: Compiler verification of event binding names similar to property binding #17483

Closed

Description

@stringham

I'm submitting a ...


[ ] Regression (behavior that used to work and stopped working in a new release)
[ ] Bug report 
[X] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

When parsing templates, Angular will complain if you attempt to bind to a property that isn't a known property:

`Can't bind to '${boundProp.name}' since it isn't a known property of '${elementName}'.`;

(

let errorMsg =
`Can't bind to '${boundProp.name}' since it isn't a known property of '${elementName}'.`;
if (elementName.startsWith('ng-')) {
errorMsg +=
`\n1. If '${boundProp.name}' is an Angular directive, then add 'CommonModule' to the '@NgModule.imports' of this component.` +
`\n2. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.`;
} else if (elementName.indexOf('-') > -1) {
errorMsg +=
`\n1. If '${elementName}' is an Angular component and it has '${boundProp.name}' input, then verify that it is part of this module.` +
`\n2. If '${elementName}' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.` +
`\n3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.`;
}
)

This is really helpful when changing @Input() names on existing components. Is it possible to have similar verification for @Output() names?

cc: @tbosch

Activity

  1. added
    featureLabel used to distinguish feature request from other issues
    on Jul 11, 2017
  2. intellix commented on Jan 18, 2018

    @intellix

    Getting runtime errors here as they're not caught by AOT. When we don't import a module containing an event binding directive, it just causes nothing to happen in production:

    Example: https://stackblitz.com/edit/angular-ccug8k?file=app%2Fapp.component.html

    Confirm directive:

    import { Directive, HostListener, Output, EventEmitter } from '@angular/core';
    
    @Directive({
      selector: '[appConfirm]'
    })
    export class ConfirmDirective {
    
      @Output() appConfirm = new EventEmitter<boolean>();
    
      constructor() { }
    
      @HostListener('click')
      onClick() {
        const result = confirm('Are you sure?');
        this.appConfirm.next(result);
      }
    
    }

    Usage:

    <button (appConfirm)="$event && hello()">Confirm greeting</button>
  3. added this to the Backlog milestone on Jan 23, 2018
  4. trotyl commented on Feb 17, 2018

    @trotyl
    Contributor

    Relates to #3426

  5. pkozlowski-opensource commented on Oct 29, 2018

    @pkozlowski-opensource
    Member

    This is a duplicate of #3426

  6. angular-automatic-lock-bot commented on Sep 14, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  7. locked and limited conversation to collaborators on Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimefeatureLabel used to distinguish feature request from other issues

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions