[英]Angular - changing ngModel value manually doesn't detect the value as valid
I'm changing the value of a select in my template: 我正在更改模板中的选择值:
<select id="CollaboratorId"
name="CollaboratorId"
formControlName="CollaboratorId"
class="form-control col-sm-8"
[(ngModel)]="SelectedUser.CollaboratorId"
(change)="onUserChange($event.target.value)" required>
<option [ngValue]="undefined">Select Collaborator</option>
<option *ngFor="let collaborator of CollaboratorsList" [ngValue]="collaborator.collaboratorId">{{collaborator.collaboratorFullName}}</option>
</select>
From my component with its ngModel name like this: 从我的组件中,其ngModel名称如下所示:
this.SelectedUser.CollaboratorId = data.collaboratorId;
When running my program I can see indeed the value has changed, however because the value wasn't selected on change it's not being registered as valid. 运行程序时,我确实可以看到该值已更改,但是由于更改时未选择该值,因此未注册为有效值。 I know there's no way to change a form's control to valid, so is there a method to instead trigger the (change)?
我知道没有办法将窗体的控件更改为有效控件,因此是否有方法代替触发(更改)? Thanks in advance.
提前致谢。
I think it is not working properly because you are mixing reactive and template driven forms. 我认为它不能正常工作,因为您混合了反应形式和模板驱动形式。 Try removing [(ngModel)].
尝试删除[(ngModel)]。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.