如何在子属性更改时触发 NgComponent 的更新 [英] How to trigger an update of NgComponent when child property changes

查看:24
本文介绍了如何在子属性更改时触发 NgComponent 的更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 AngularDart(和 Dart)的完整初学者;我遵循了教程,但我似乎无法找到答案.

I am a complete beginner to AngularDart (and Dart); I followed the tutorials but this is something I can't seem to find a answer to.

我有两个完美运行的 NgComponents:

I have two NgComponents that work perfectly:

 <colorImage car-color="ctrl.car.color"></colorImage>
 <carImage car="ctrl.car"></carImage>

我的控制器ctrl"有一个名为car"的属性,而car"有一个名为color"的属性.当car.color"发生变化时,colorButton NgComponent 会更新,但 carImage NgComponent 不会.

My controller "ctrl" has a property named "car" and "car" has a property named "color". When "car.color" changes, the colorButton NgComponent updates, but the carImage NgComponent does not.

如何在car.color"更改时触发 carImage 的更新?

How can I trigger an update of carImage when "car.color" changes?

谢谢!!

推荐答案

你必须在你的 CarImage 中设置一个手表到 car.color.这看起来如何取决于您对汽车使用的数据结构.

You have to set a watch to car.color inside your CarImage. How this looks depends on what data structure you use for car.

// constructor
CarImage(Scope scope) {
   scope.$watch(() => car.color, (color) => doSomething(color));
}

这篇关于如何在子属性更改时触发 NgComponent 的更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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