[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 ...
随机推荐
- Non-resolvable parent POM for **: Could not find artifact **
注意查看这句: 原因是本地仓库缺少了easybuy-parent:pom:0.0.1-SNAPSHOT, 原来是忘记了将父工程打包到本地仓库 ,运行聚合工程前记得先将依赖的工程都先Maven inst ...
- COGS——T 1265. [NOIP2012] 同余方程
http://cogs.pro/cogs/problem/problem.php?pid=1265 ★☆ 输入文件:mod.in 输出文件:mod.out 简单对比时间限制:1 s 内 ...
- 洛谷 P1068 分数线划定
P1068 分数线划定 题目描述 世博会志愿者的选拔工作正在 A 市如火如荼的进行.为了选拔最合适的人才,A 市对 所有报名的选手进行了笔试,笔试分数达到面试分数线的选手方可进入面试.面试分数线根 据 ...
- [Python] The get() method on Python dicts and its "default" arg
# The get() method on dicts # and its "default" argument name_for_userid = { 382: "Al ...
- M1卡操作
M1卡操作时,读取的时候,是将卡里面的1块(占16个字节)数据以十六进制字符的形式读取出来的啊!一个字节占两位16进制,因为读出来是字符.如果放在byte[]数组里,因为一个字符占一个字节,所以要用长 ...
- 【Codeforces Round #431 (Div. 2) A】Odds and Ends
[链接]点击打开链接 [题意] 让你把一个数组分成奇数个部分. 且每个部分的长度都是奇数. [题解] 很简单的脑洞题. 开头和结尾一定要为奇数,然后 n为奇数的话,就选整个数组咯. n为偶数的话,不能 ...
- amazeui学习笔记--css(基本样式2)--基础设置Base
amazeui学习笔记--css(基本样式2)--基础设置Base 一.总结 1.盒子模型:外margin,内padding,这里的内外指的边框 2.border-box:Amaze UI 将所有元素 ...
- css函数——calc()和attr()
css也有函数?好吧,我孤陋寡闻了.这里记录一下学习情况. calc()函数 定义:用于动态计算长度值 支持版本:css3 运算符前后都需要保留一个空格,例如:width: calc(100% - 1 ...
- GO语言学习(二)Windows 平台下 LiteIDE 的安装和使用
1. 安装 Go 语言并设置环境变量 参考GO语言学习(一) 2. MinGW 的下载和安装 Windows 下的 Go 调试还需要安装 MinGW. 2.1 下载安装工具的安装 最新版本下载安装工具 ...
- 【Codeforces Round #433 (Div. 1) C】Boredom(二维线段树)
[链接]我是链接 [题意] 接上一篇文章 [题解] 接(点我进入)上一篇文章. 这里讲一种用类似二维线段树的方法求矩形区域内点的个数的方法. 我们可以把n个正方形用n棵线段树来维护. 第i棵线段树维护 ...