validate.component.ts 1.27 KB
import { Component, ViewContainerRef, ViewChild, AfterViewInit } from '@angular/core';
import { FormGroup } from '@angular/forms';

import { AgEditorComponent } from 'ag-grid-ng2/main';

@Component({
    selector: 'editor-cell',
    templateUrl: './validate.component.html',
})
export class ValidateComponent implements AgEditorComponent, AfterViewInit {
    private params: any;
    private value: string = null;

    @ViewChild('container', {read: ViewContainerRef}) public container: any;
    public form: FormGroup;
    public field: string;

    ngAfterViewInit(): void {
        this.container.element.nativeElement.focus();
    }

    agInit(params: any): void {
        this.params = params;
        this.form = params.form;
        this.field = params.field;
    }

    getValue(): any {
        console.log('From getter', this.value);
        return this.value;
    }

    setValue(value: string): void {
        this.value = value;
        console.log('From setter', this.value);
    }

    isPopup(): boolean {
        return true;
    }

    editorChange(event): boolean {
        event.preventDefault();
        event.stopPropagation();
        this.setValue(this.form.value[this.field]);
        this.params.api.stopEditing();
        event.stopPropagation();
        return false;
    }
}