如何在子属性更改时触发 NgComponent 的更新

编程入门 行业动态 更新时间:2024-10-25 14:35:05
本文介绍了如何在子属性更改时触发 NgComponent 的更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我是 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-22 12:11:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023521.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   如何在   NgComponent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!