mgechev / angular2-style-guide

[Deprecated] Community-driven set of best practices and style guidelines for Angular 2 application development
https://mgechev.github.io/angular2-style-guide/
1.2k stars 98 forks source link

Name events without prefix 'on' #27

Closed sbley closed 8 years ago

sbley commented 8 years ago

I would suggest the following naming convention for events:

Name events without the prefix 'on'. Name your event handler methods with the prefix 'on' followed by the event name.

/* WRONG */
<my-voter (onVoted)="onVoted($event)"></my-voter>
/* CORRECT */
<my-voter (voted)="onVoted($event)"></my-voter>

Why?: This is to be consistent with built-in events like button clicks:

<button (click)="showDetails()">Show Details</button>

Why?: Angular allows for an alternative syntax on-*. If the event itself was prefixed with 'on' this would result in an on-onEvent binding expression.

/* CORRECT */
<my-voter (voted)="onVoted($event)"></my-voter>
<my-voter on-voted="onVoted($event)"></my-voter>
mgechev commented 8 years ago

This sounds good to me. Do you want to open a PR?