melina
melina

Reputation: 65

bind to an input on form

What i'm trying to do, is get the value of an input on my form and affect it to a variable on my Typescript class, here is my template :

<form [ngFormModel]="form" (ngSubmit)="save()">
    <fieldset>
        <legend>
            Action
        </legend>
        <div class="form-group">
            <label for="label">Label</label>
            <input ngControl="label" type="text" class="form-control">
        </div>

For example here i want to get the value of the input called label when the user save the form and simply affect it like this :

export class ActionFormComponent {
    form: ControlGroup;
    _label: any;
    constructor() {

    }

    print() {
        this_label = this.form.label;
        console.log(this._label);
    }
}

Upvotes: 0

Views: 76

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657058

ngModel does what you want:

<input ngControl="label" type="text" class="form-control" [(ngModel)]="label">

Upvotes: 1

Related Questions