我尝试将数据发送到我的 Angular 项目中的 Dropbox,但我无法将任何选定的数据发送到该 Dropbox。当我在主表中单击更新按钮时我想要它。我使用 patchvalue 将数据获取到其他文本字段,但下拉值即将到来。
补充我的评论 在 .ts 中
variable=''
在 .html 中
<select [(ngModel)]="variable">
<option value='' disable hidden>Select customer</option>
<option *ngFor="let customerValue of customers [value]="customerValue.id">
{{customerValue.userName}}</option>
</select>
<button (click)="getCustomer()">get data</button>
您可以使用 getCustomer 函数
getCustomer()
{
//in this.value you get the "id" of the selected customer
console.log(this.value)
//If you need the customer you need find in the list of the customers
console.log(this.customers.find(x=>x.id=this.value))
}
注意:您需要在模块中导入 FormsModule 注意2:你可以用这种方式“分割”[(ngModel)]
<select [ngModel]="variable"
(ngModelChange)="variable=$event;doSomething($event)">
...
</select>
doSomething(value:any)
{
//here value is the "id" of the selected customer
}
NOTE4:真正看到你的 GetOrderById,我认为你应该使用 ReactiveFormsControls。但在表单中,您应该使用客户的“id”,而不是客户名称。有些类似于
<form [formGroup]="orderForm">
<select formControlName="customerId"...>
</select>
</form>