Added input validation

This commit is contained in:
NejcZdovc
2016-11-17 08:10:31 +01:00
committed by József Farkas
parent 11c79fd312
commit 1ea1d0c2a2
4 changed files with 27 additions and 4 deletions

View File

@@ -1,4 +1,7 @@
import { ChangeDetectionStrategy, Component, ElementRef, Input, Renderer, ViewChild } from '@angular/core';
import {
ChangeDetectionStrategy, Component, ElementRef, Input, OnChanges, Renderer,
ViewChild
} from '@angular/core';
import { Store } from '@ngrx/store';
@@ -13,7 +16,7 @@ import { AppState } from '../../../store/index';
styles: [require('./macro-header.component.scss')],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MacroHeaderComponent {
export class MacroHeaderComponent implements OnChanges {
@Input() macro: Macro;
@Input() isNew: boolean;
@ViewChild('macroName') macroName: ElementRef;
@@ -35,6 +38,11 @@ export class MacroHeaderComponent {
}
editMacroName(name: string) {
if (name.length === 0) {
this.renderer.setElementProperty(this.macroName.nativeElement, 'value', this.macro.name);
return;
}
this.store.dispatch(MacroActions.editMacroName(this.macro.id, name));
}
}