Angular 2 + Ionic 2:检测对象是否被修改 [英] Angular 2 + Ionic 2: Detect if an object was modified

查看:20
本文介绍了Angular 2 + Ionic 2:检测对象是否被修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问) 如果我有一个具有大量属性的对象,所有属性都绑定到表单中的字段,我如何在对象发生更改时进行捕获?

我不想在每个字段上放置 (blur) 事件,因为页面已经很重了,这可能会导致页面上的听众太多.

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.

例如

对象:

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

表格:

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

推荐答案

您可以使用表单对象并检查表单是否已更改.

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

我知道最新版本的 Angular2 和 Ionic2 与新的 Forms 模块存在一些问题,但这是我的建议.

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/表单.html

这篇关于Angular 2 + Ionic 2:检测对象是否被修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆