[英]Angular Dropdown Change() vs valueChanges.subscribe
I have an Angular form built using Reactive Forms.我有一个使用反应式 Forms 构建的 Angular 表单。 The form contains 3 select elements.
该表单包含 3 个 select 元素。 I want to add the value change detection to one dropdown and other two will change accordingly to the values of the first dropdown.
我想将值更改检测添加到一个下拉列表中,其他两个将根据第一个下拉列表的值进行相应更改。 Between Change() and valueChanges.subscribe , which will be the best to use and what is the difference.
在Change()和valueChanges.subscribe之间,这将是最好用的,有什么区别。
They are fundamentally the same thing, each time the value of your dropdown changes, a function that change the value of the two other dropdowns is executed.它们本质上是一样的,每次下拉列表的值发生变化时,都会执行一个改变其他两个下拉列表值的 function。
valueChanges
is an Observable, you have to unsubscribe from it at some point, for instance when the component is destroyed. valueChanges
是一个 Observable,你必须在某些时候取消订阅它,例如当组件被销毁时。
it depends on your use case这取决于您的用例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.