简体   繁体   English

深度监视无效

[英]Deep watch doesn't work

Have plunk: http://plnkr.co/edit/hdstMO7BDGGsNRUDJhQS?p=preview pl了一下: http ://plnkr.co/edit/hdstMO7BDGGsNRUDJhQS? p= preview

Deep watching fires when change 'name' or 'surname', but doesn't fire when change 'phones'. 更改“名称”或“姓氏”时会触发深度监视,但更改“电话”时不会触发深度监视。 Why? 为什么? How can i watch full object or how to do this in angular-way? 我如何观看整个物体或如何以角度方式观看?

The problem is in this line: 问题在这一行:

<span contenteditable ng-model="phone">{{ phone }}</span>

Since the phones is an array of primitive values, ngRepeat will create a copy of each phone on a scope created by ngRepeat . 由于电话是原始值的阵列, ngRepeat将在由创建的范围建立的每个电话的副本ngRepeat Then your ngModel is bound to this copy so the original object isn't changed and this is why your deep watch doesn't fire. 然后,您的ngModel便会绑定到此副本,因此原始对象不会更改,这就是您的深入观察无法触发的原因。

The remedy is simple, change the line in question to 解决方法很简单,将相关行更改为

<span contenteditable ng-model="contact.phones[$index]">{{ phone }}</span>

and you should be set: http://plnkr.co/edit/dxKBw3uZqSA4mfCDU2h1?p=preview 并且应该设置为: http : //plnkr.co/edit/dxKBw3uZqSA4mfCDU2h1?p=preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM