[Angular] Updating and resetting FormGroups and FormControls
If you want to reset or just update field value, you can do:
reset: reset({key: value, k2:v2});
update:
1. patchValue({k: v}); update part of form fields
2. setValue({k:v, k1: v1...}); update whole form fields.
reset:
onAdd() {
this.added.emit(this.parent.get('selector').value);
this.parent.get('selector')
.reset({
quantity: ,
product_id: ''
})
}
All the 'dirty, touched, valid' props on form will also be reset.
Update:
onAdd() {
this.added.emit(this.parent.get('selector').value);
this.parent.get('selector')
.patchValue({
product_id: ''
})
}
For 'patchValue', we only need to update part of props, not all of them.
onAdd() {
this.added.emit(this.parent.get('selector').value);
this.parent.get('selector')
.setValue({
quantity: ,
product_id: ''
})
}
For 'setValue', you have to update all the fields, otherwise it will throw error.
[Angular] Updating and resetting FormGroups and FormControls的更多相关文章
- angular reactive form
这篇文章讲了angular reactive form, 这里是angular file upload 组件 https://malcoded.com/posts/angular-file-uploa ...
- 2015前端各大框架比较(angular,vue,react,ant)
前端流行框架大比拼 angular vue react ant-design angularjs angular是个MVVM的框架.针对的是MVVM这整个事.angular的最主要的场景就是单页应用, ...
- Angular DirtyChecking(脏值检查) $watch, $apply, $digest
Dirty Checking (脏值检查) Digest cycle and $scope Digest cycle and $scope First and foremost, AngularJS ...
- [转]Angular: Hide Navbar Menu from Login page
本文转自:https://loiane.com/2017/08/angular-hide-navbar-login-page/ In this article we will learn two ap ...
- Angular 2 to Angular 4 with Angular Material UI Components
Download Source - 955.2 KB Content Part 1: Angular2 Setup in Visual Studio 2017, Basic CRUD applicat ...
- react和vue,angular的比较
就这几天我所了解到react情况和大家探讨一下子react的知识: react由facebook团队维护的一套框架,已经应用在instagram网站上了,react以其独特的性能优化方案,正在被越来越 ...
- Angular基础(五) 内建指令和表单
Angular提供了一些内建的指令,可以作为属性添加给HTML元素,以动态控制其行为. 一.内建指令 a) *ngIf,可以根据条件来显示或隐藏HTML元素. <div *ngIf='a&g ...
- TWO PHASES OF ANGULAR 2 APPLICATIONS
Angular 2 separates updating the application model and reflecting the state of the model in the view ...
- CHANGE DETECTION IN ANGULAR 2
In this article I will talk in depth about the Angular 2 change detection system. HIGH-LEVEL OVERVIE ...
随机推荐
- JavaScript--数据结构之栈
4.1栈是一种高效的数据结构,是一种特殊的列表.栈内元素只能通过列表的一端访问,也就称为栈顶.后入的先出的操作.Last in First out.所以他的访问每次是访问到栈顶的元素,要想访问其余的元 ...
- Ubuntu系统简介
1.ubuntu 远程连接 需要开启ssh 服务 sudo apt-get install openssh-server service ssh start|stop|restart 2.查看Linu ...
- [Redux] Understand Redux Higher Order Reducers
Higher Order Reducers are simple reducer factories, that take a reducer as an argument and return a ...
- HDU 1848(sg博弈) Fibonacci again and again
Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- php的数据类型和变量的作用域
1)php支持例如以下所看到的的基本数据类型: Integer(整数).Float(浮点数).String(字符串).Boolean(布尔值).Array(数组).Object(对象),此外还有两个特 ...
- event事件对象 兼容写法:var oEvent=ev||event;和取消事件冒泡
要在整个页面添加事件要使用document,例如要捕抓鼠标位置 document.onclink=function(ev) //FireFox Chrome默认都是有一个值传进来的 { var oE ...
- HDF文件的显示策略
作者:朱金灿 来源:http://blog.csdn.net/clever101 hdf格式(类似还有netcdf格式)格式是国际上通用的遥感数据格式.它们都是采用不规则存储的格式,就是在一个hdf文 ...
- amazeui学习笔记--css(常用组件7)--输入框组Input-group
amazeui学习笔记--css(常用组件7)--输入框组Input-group 一.总结 1.使用:Input group 基于 Form 组件和 Button 组件扩展,依赖这两个组件.在容器上添 ...
- python获取序列中最大值
test =[ [1, 2, 3], [4, 5, 6], [7, 8, 9]] #这个就可以看做是二维数组了,直接创建print(test)print(test[:][1]) ...
- 使用Surging Mqtt 开发基于WS的MqttClient客户端
原文:使用Surging Mqtt 开发基于WS的MqttClient客户端 最近一段时间由于要做一套智能设备系统,而有幸了解到Surging中的Mqtt broker,学习了很多东西本篇文章基于Su ...