For example we have built a form:

  form = this.fb.group({
store: this.fb.group({
branch: '',
code: ''
}),
selector: this.createStock({}),
stock: this.fb.array([])
});

We want to reponse to each time 'stock' value changes.

To do that we can subscrube 'valueChanges' for form.

Notice that, 'valueChanges' is an Observable, you need to subscribe to it, And it not only exists for 'form', also for 'formControl, formGroup, formArray':

this.form.get('stock')
.valueChanges
.subscribe(...)

If you want to give an initial value, you can use 'startWith' from 'rxjs/add/opreator/startWith'.

      this.form.get('stock')
.valueChanges
.startWith(this.form.get('stock').value)
.subscribe((stocks) => {
this.total = this.calculateTotal(stocks);
}) calculateTotal(stocks: Item[]): number {
return stocks.reduce((acc, next) => {
return acc + (Number(next.quantity) * Number(this.productMap.get(next.product_id).price))
}, )
}

最新文章

  1. in addition to 和 except for
  2. mui slider 改变默认index
  3. 6月辞职->帝都生活
  4. preventDefault()方法
  5. spring Integration服务总线
  6. 【Android车载系统 News | Tech 1】News 谷歌开发车载Android系统 2014-12-19
  7. Object-C - 类的定义
  8. ARM GCC CodeSourcery 下载地址
  9. Js监控回车事件
  10. iOS_25彩票_幸运转盘
  11. python在windows和linux环境的进程对比
  12. JAVAscript学习笔记 js事件 第一节 (原创) 参考js使用表
  13. two sum --无脑法
  14. This Android SDK requires Android Developer Toolkit version 17.0.0 or above. Current version is 10.0.0.v201102162101-104271. Please update ADT to the latest version.
  15. SmileyCount.java笑脸加法程序代写(QQ:928900200)
  16. 杭电ACM 1297 Children’s Queue
  17. 升级my.cnf注意
  18. 使用Prometheus+Grafana监控MySQL实践
  19. CSS之Header--我的头部我做主
  20. Azkaban学习笔记(一)

热门文章

  1. Keil 编译环境之在线仿真调试问题
  2. GeoServer 常见问题总结 (转)
  3. (cocos2d-js游戏)測试你的反应速度----------基本逻辑(上)
  4. js进阶 14-7 jquery的ajax部分为什么需要对表单进行序列化
  5. event事件对象 兼容写法:var oEvent=ev||event;和取消事件冒泡
  6. Android RxBus的实现及简单使用
  7. ArcGIS在线帮助的使用指南
  8. OC中对于属性的总结(@property)
  9. APP测试10点
  10. Ansible 部署