Or, as an alternative, you can use more appropriate Form controls designed for angular 2. ( learn more here )
Example:
Typescript
import {Component, Input} from '@angular/core'; import {FORM_DIRECTIVES, FormBuilder, ControlGroup, AbstractControl} from '@angular/common'; import {IONIC_DIRECTIVES} from 'ionic-angular'; @Component({ selector: 'chat-form', templateUrl: '/client/components/chat-form/chat-form.html', directives: [IONIC_DIRECTIVES, FORM_DIRECTIVES], pipes: [], styleUrls: [] }) export class ChatFormComponent { chatForm:ControlGroup; messageInput:AbstractControl; constructor(private translate:TranslateService, private formBuilder:FormBuilder) { this.chatForm = formBuilder.group({messageInput: ['']}) this.messageInput = this.chatForm.controls['messageInput']; } sendMessage() { console.log('sendMessage: ', this.messageInput.value); } }
Template
<form [ngFormModel]="chatForm" (ngSubmit)="sendMessage()"> <ion-input type="text" [ngFormControl]="messageInput" placeholder="{{'chat.form.placeholder' | translate }}"></ion-input> <button fab> <ion-icon name="send"></ion-icon> </button> </form>
source share