Skip to content

Instantly share code, notes, and snippets.

@armanozak
Last active May 9, 2019 08:25
Show Gist options
  • Save armanozak/a4102e39b640fdf84544a9d10e674dc0 to your computer and use it in GitHub Desktop.
Save armanozak/a4102e39b640fdf84544a9d10e674dc0 to your computer and use it in GitHub Desktop.
An Abstract Input Component Extending Abstract NgModel Component #blog
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { AbstractNgModelComponent } from './ng-model.component';
@Component({ template: '' })
export class AbstractInputComponent extends AbstractNgModelComponent<string> {
@Input()
readonly: boolean = false;
@Input()
required: boolean = false;
@Input()
placeholder: string = '';
@Input()
type: string = 'text';
@Output()
onBlur = new EventEmitter<void>();
@Output()
onFocus = new EventEmitter<void>();
get inputReadonly(): boolean {
return this.readonly || typeof this.readonly !== 'boolean';
}
get inputRequired(): boolean {
return this.required || typeof this.required !== 'boolean';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment