简体   繁体   English

带有数字的角度补丁值,用于反应形式的多选

[英]Angular patch value with numbers for multiselect in reactive forms

Hi i'm wondering why the patch value doesnt work with when using numbers.嗨,我想知道为什么在使用数字时补丁值不起作用。 I have a select which gets populated with a number for the value and i get a array of numbers from the backend which i use to set the value.我有一个选择,其中填充了一个数字作为值,我从后端获取了一个数字数组,我用它来设置值。 But this doesnt work.但这不起作用。 But when the array values are converted to string it works.但是当数组值转换为字符串时,它就起作用了。

<mat-select formControlName="location" placeholder="Event Type" >
   <mat-option  *ngFor='let loc of locations'  value="{{loc.id}}">{{loc.name}}</mat-option>
</mat-select>

this is used to set the value这用于设置值

  setParticipants(value) {
    this.AddEventForm.patchValue({
      participants: value
    });
  }

the value that gets passed to set participants is [84,118] is something like this传递给集合参与者的值是 [84,118] 是这样的

EDIT- Created a stackblitz https://stackblitz.com/edit/angular-dvb4y5编辑 - 创建了一个 stackblitz https://stackblitz.com/edit/angular-dvb4y5

The way of binding the property value makes the difference.绑定属性value的方式有所不同。

If you bind like below, it will convert the data type to string .如果你像下面这样绑定,它会将数据类型转换为string

 <option *ngFor='let val of list' value='{{val.id}}'>{{val.name}}</option>

If you bind as below, it will bind the actual data type.如果按如下方式绑定,它将绑定实际的数据类型。

 <option *ngFor='let val of list' [value]='val.id'>{{val.name}}</option>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 角度绑定数字数组到普通引导多选值(反应形式) - angular binding numbers array to plain bootstrap multiselect value (reactive forms) 将值修补到 Angular 反应 forms 中的多个 formArray - Patch value to multiple formArray in Angular reactive forms 补丁值不适用于嵌套输入反应形式 Angular 5 - Patch value not working with nested inputs Reactive forms Angular 5 如何以角度反应形式修补或设置特定输入字段的值 - How to patch or set value for particular input field in angular reactive forms 如何在 angular 中修补嵌套反应 forms 中的 select 框值? - How to patch select box value inside nested reactive forms in angular? 带有 Reactive Forms 补丁值的 NgRx - NgRx with Reactive Forms Patch Value 如何使用反应式 forms 在 Angular 多选上设置选择? - How to set selections on an Angular multiselect with reactive forms? 反应形式的数字数组,角度为6? - Array of numbers in Reactive Forms, Angular 6? 如何以反应形式修补多选下拉列表(primeng 组件)的值? - How to patch the value of multiselect dropdown (primeng component) in a reactive form? 如何在 angular 正式反应式 forms 的多选中单击元素时绑定组件 - How to Bind a component on click of element in multiselect of angular formly Reactive forms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM