Search code examples
angulartypescriptionic-frameworkionic2ionic3

Angular 2 + Ionic 2: Detect if an object was modified


Q) If I've got an object with loads of properties, all bound to fields in a form, how do I catch when the object has changed?

I don't want to put (blur) events on every field as the page is quite heavy already and this could lead to way too many listeners on the page.

E.g

Object:

var person = {
    name: string,
    email: string,
    phone: string
};

Form:

<input [(ngModel)]="person.name" type="text" />
<input [(ngModel)]="person.email" type="text" />
<input [(ngModel)]="person.phone" type="text" />

Solution

  • you can use a form object and check if the form has changed.

    I know that there have been some issues with latest release of Angular2 and Ionic2 with the new Forms module, but that would be my suggestion.

    https://angular.io/docs/ts/latest/guide/forms.html