[英]Why I can't update the value of an Angular reactive form field with a calculated value?
[英]Why doesn't my Reactive Form in Angular 4 update the value when set by datetimepicker
我正在尝试向我的Angular 4 Metronic网站添加一个datetimepicker 。 我已将其添加到我的反应式表单中,如下所示:
<input formControlName="timeOfRemoval" data-provide="datetimepicker" class="form-control m-input" id="timeOfRemoval" placeholder="Select date & time" readonly="" type="text">
现在,这可以很好地创建选择器,并且还可以在字段中设置值。 但是没有发生的是Reactive Form
正在获取价值的变化。
当我要提交表单时, timeOfRemoval
的值保持为空。 当我删除readonly
,选择一个日期时间并通过添加和删除空格来更新值,它确实可以工作。
当然,这不是我想要的,我希望我的Reactive Form
能够检测到更改。 我该怎么做?
在component.ts文件中建立反应形式之后,如果执行以下操作,它是否注册了值的更改?
this.myReactiveForm.get('timeOfRemoval').valueChanges.subscribe(val => {
console.log('new value is: ' + val);
// if it is showing the value is changing, then maybe save
// that value to a different variable in this component and use
// it when the form is submitted
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.