generator-fountain-angular2
Version:
Yeoman Fountain generator to scaffold a webapp with Angular 2 written in ES6 (Babel), TypeScript through Webpack or SystemJS including tools Gulp 4, ESLint, Browsersync and Karma
36 lines (30 loc) • 914 B
text/typescript
import {Component, Input, Output, EventEmitter, ElementRef, Renderer, ViewChild, AfterViewInit} from '@angular/core';
export class TodoTextInputComponent implements AfterViewInit {
input: ElementRef;
newTodo: boolean;
editing: boolean;
placeholder: string = '';
onSave: EventEmitter<any> = new EventEmitter(false);
text: string = '';
constructor(private renderer: Renderer) {}
ngAfterViewInit() {
this.renderer.invokeElementMethod(this.input.nativeElement, 'focus', []);
}
handleBlur() {
if (!this.newTodo) {
this.onSave.emit(this.text);
}
}
handleSubmit(e: any) {
if (e.keyCode === 13) {
this.onSave.emit(this.text);
if (this.newTodo) {
this.text = '';
}
}
}
}