Skip to content

Instantly share code, notes, and snippets.

@arturovt
Last active June 6, 2019 23:17
Show Gist options
  • Save arturovt/eed61e959eddeba3ddbd924e64324d39 to your computer and use it in GitHub Desktop.
Save arturovt/eed61e959eddeba3ddbd924e64324d39 to your computer and use it in GitHub Desktop.
import { Component, ChangeDetectionStrategy, Input, ElementRef } from '@angular/core';
@Component({
selector: 'app-button',
templateUrl: './button.component.html',
styleUrls: ['./button.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ButtonComponent {
@Input()
public color: string = null;
@Input()
public shouldEmit = false;
constructor(private host: ElementRef<HTMLElement>) {}
public click(): void {
if (this.shouldEmit) {
this.host.nativeElement.dispatchEvent(
new CustomEvent('click')
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment