Working with inputs and outputs while following Angular 2's styleguide naming convention
Initially, my directive was defined like this:
...
inputs: [
'onOutside'
]
...
export class ClickOutsideDirective {
@Output() onOutside: EventEmitter<any> = new EventEmitter();
}
However, the styleguide recommends not using the prefix on
for outputs, as Angular 2 supports the on-
syntax in templates.
Attempting to adjust it to:
@Input() outsideClick: any;
@Output() outsideClick: EventEmitter<any> = new EventEmitter();
But struggling to differentiate between the @Input
and Output
names without the on
prefix.
In the previous approach, naming both the @Input
and @Output
the same worked, but errors occur when declared within the exported class.
Renaming @Input
to outside
and @Output
to outsideClick
seems counterintuitive since they represent the same function. outside
is the action triggered by outsideClick
.
Furthermore, if outside
and outsideClick
are no longer named identically, outsideClick
may not know which function to execute.
How can I effectively name the @Input
and @Output
variables so that functionality is maintained while making sense, similar to the original example?
EDIT:
Example of how to use:
<div clickOutside [exceptions]="['.toggler']" (outside)="doSomethingOnOutsideClick()"></div>