angular - Angular 7+中 react 形式的.value和.setValue之间的差异

标签 angular

我想完全理解在angular 7+中.value和.setValue之间有什么区别,在哪种情况下适合使用.value或.setValue?

示例1:this.createLocForm.setValue(data);
示例2:this.data = this.createLocForm.value

最佳答案

示例1:this.createLocForm.setValue(data);

Use the setValue() method to set a new value for individual control. The setValue() method strictly adheres to the structure of the form group and replaces the entire value for the control. Please read this for more details



示例2:this.data = this.createLocForm.value

This is a read-only property. You can't assign any value for this property. You can only do read the control values by using this property.

关于angular - Angular 7+中 react 形式的.value和.setValue之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59588097/

相关文章:

javascript - 关于 Angular 中构造函数和 ngOnInit() 之间逻辑的混淆

带有正文的 Angular HttpClient Get 方法

后端的 Angular 代理不起作用?

http - Angular2 http 获取请求结果为 404

angular - 现在用工作项目更新 ng-cli "Cannot GET/"?

javascript - 等待 Observable 完成以提交表单

angular - 特定实体的大量 Action /效果

javascript - 单击时将 ngFor 中的项目传递给其他页面的对象

angular - 无法在 [(ngModel)] 内使用三元 if 语句

javascript - Angular Firebase 如何按字段查找和检索数据