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

查看:189
本文介绍了当子属性更改时,如何触发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颜色。
当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 .color更改?

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天全站免登陆