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

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

问题描述

Q)如果我有一个带有大量属性的对象,所有属性都绑定到表单中的字段,那么当对象发生更改时如何捕获?

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

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 / forms.html

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

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