我有2个不同的嵌套对象,我需要知道它们的嵌套属性是否有差异.
var a = {};
var b = {};
a.prop1 = 2;
a.prop2 = { prop3: 2 };
b.prop1 = 2;
b.prop2 = { prop3: 3 };
Run Code Online (Sandbox Code Playgroud)
使用更多嵌套属性,对象可能会复杂得多.但这个是一个很好的例子.我可以选择使用递归函数或者使用lodash ...
我想听我的表单的值更改,但不是整个表单,而是仅针对已更改的表单控件。
例如,如果我的表格看起来像这样。
this.form = this._fb.group({
firstName: [''],
lastName: [''],
... // other stuff.
});
Run Code Online (Sandbox Code Playgroud)
如果我订阅 valuechanges
this.form.valueChanges.subscribe((e) => {
console.log(e);
});
Run Code Online (Sandbox Code Playgroud)
然后在表单中填写名字将导致整个表单值对象的打印输出。
{名字:'输入',姓氏:'',...}
但我想知道的是哪个表单控件(在本例中为firstName)在不订阅每个单独的表单控件的情况下被更改。这样我想要的输出只是
{名字:'输入'}