[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 ...
随机推荐
- 在window编写好的网站往linux上发布
得知ASP.NET CORE可以跨平台,我内心很躁动,毕竟自己喜欢的,之前没有学过linux导致一开始上手linux有点困难,按照https://www.microsoft.com/net/core# ...
- ED/EP系列1《简单介绍》
电子存折(ED:ElectronicDeposit)一种为持卡人进行消费.取现等交易而设计的支持个人识别码(PIN)保护的金融IC卡应用. 它支持圈存.圈提.消费和取现等交易. 电子钱包(EP:Ele ...
- 5. Spring Boot 拦截器
转自:https://blog.csdn.net/catoop/article/details/50501696
- ios系统和某些移动端background-attachment:fixed不兼容性
固定背景不动:background-attachment:fixed; ios系统和某些移动端background-attachment:fixed不兼容性,没有任何效果,但可以hack一下就可以了, ...
- GO语言学习(十三)Go 语言变量作用域
Go 语言变量作用域 作用域为已声明标识符所表示的常量.类型.变量.函数或包在源代码中的作用范围. Go 语言中变量可以在三个地方声明: 函数内定义的变量称为局部变量 函数外定义的变量称为全局变量 函 ...
- LeetCode Algorithm 133_Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's ...
- call,apply,求最大最小值,平均数等基础编程知识
CALL/APPLY.一些编程基础以及一些基础知识.正则 call.apply.bind 求数组的最大值和最小值: 数组排序(SORT的原理->localeCompare实现汉字比较),取头取尾 ...
- SQL判断空值、nvl处理与JOIN的使用
LIKE子句会影响查询性能,所以在明确知道字符个数时,应该使用'_',而不使用'%'. 判断空值/非空值 SELECT select_list FROM table_list/view_list WH ...
- 【例题 6-19 UVA - 1572】Self-Assembly
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 旋转和翻转,会发现. 如果可以顺着某个方向一直放的话. 总是能转换成往下或者往右连的. 则只要能够出现一个连接顺序的循环,则总是有解 ...
- pat 2-05. 求集合数据的均方差(水题)
代码: #include<cstdio> #include<iostream> #include<cmath> using namespace std; doubl ...