Опровергнутый слушатель keyUp на сгенерированном поле ввода - PullRequest
0 голосов
/ 22 декабря 2018

Я создал приложение JHipster, и теперь я хочу воздействовать на изменения в форме ввода в форме редактирования сущности по умолчанию, сгенерированной JHipster.

Я думал, что это будет хорошим решением: https://stackoverflow.com/a/43999461/4397899

Но так как сгенерированный по умолчанию компонент JHipster не имеет члена ViewChild для каждого поля, я не знаю, как применить это решение.

Я думаю, что до сих пор понял, чтовходные данные связываются с объектом TestEntity в файле testentity-update.component.ts.Нужно ли добавлять вторую директиву [(ngModel)] для привязки ввода к аннотированному элементу @ViewChild файла .ts?(это вообще возможно?)

(testentity-update.component.html)

<div class="row justify-content-center">
<div class="col-8">
    <form name="editForm" role="form" novalidate (ngSubmit)="save()" #editForm="ngForm">
        <h2 id="jhi-testentity-heading" jhiTranslate="sampleApp.testentity.home.createOrEditLabel">Create or edit a Testentity</h2>
        <div>
            <jhi-alert-error></jhi-alert-error>
            <div class="form-group" [hidden]="!testentity.id">
                <label for="id" jhiTranslate="global.field.id">ID</label>
                <input type="text" class="form-control" id="id" name="id"
                    [(ngModel)]="testentity.id" readonly />
            </div>
            <div class="form-group">
                <label class="form-control-label" jhiTranslate="sampleApp.testentity.value" for="field_value">Value</label>
                <input type="text" class="form-control" name="value" id="field_value"
                    [(ngModel)]="testentity.value" />
            </div>

        </div>
        <div>
            <button type="button" id="cancel-save" class="btn btn-secondary"  (click)="previousState()">
                <fa-icon [icon]="'ban'"></fa-icon>&nbsp;<span jhiTranslate="entity.action.cancel">Cancel</span>
            </button>
            <button type="submit" id="save-entity" [disabled]="editForm.form.invalid || isSaving" class="btn btn-primary">
                <fa-icon [icon]="'save'"></fa-icon>&nbsp;<span jhiTranslate="entity.action.save">Save</span>
            </button>
        </div>
    </form>
</div>

(testentity-update.component.ts)

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs';

import { ITestentity } from 'app/shared/model/testentity.model';
import { TestentityService } from './testentity.service';

@Component({
    selector: 'jhi-testentity-update',
    templateUrl: './testentity-update.component.html'
})
export class TestentityUpdateComponent implements OnInit {
    testentity: ITestentity;
    isSaving: boolean;

    constructor(protected testentityService: TestentityService, protected activatedRoute: ActivatedRoute) {}

    ngOnInit() {
        this.isSaving = false;
        this.activatedRoute.data.subscribe(({ testentity }) => {
            this.testentity = testentity;
        });
    }

    previousState() {
        window.history.back();
    }

    save() {
        this.isSaving = true;
        if (this.testentity.id !== undefined) {
            this.subscribeToSaveResponse(this.testentityService.update(this.testentity));
        } else {
            this.subscribeToSaveResponse(this.testentityService.create(this.testentity));
        }
    }

    protected subscribeToSaveResponse(result: Observable<HttpResponse<ITestentity>>) {
        result.subscribe((res: HttpResponse<ITestentity>) => this.onSaveSuccess(), (res: HttpErrorResponse) => this.onSaveError());
    }

    protected onSaveSuccess() {
        this.isSaving = false;
        this.previousState();
    }

    protected onSaveError() {
        this.isSaving = false;
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...