[英]Mat Select is not getting selected value angular 6 TS
Mat Select is not set selected value when I do update operation. 我执行更新操作时,未将Mat Select设置为选定值。 I want to show selected value when I click on update so other textboxes are getting correct value but mat-select doesn't, If I replace mat-select with simple textbox so it's getting correct value. 我想在单击更新时显示选定的值,以便其他文本框获得正确的值,但mat-select却没有,如果我将mat-select替换为简单的文本框以使其获得正确的值。
HTML HTML
<mat-select placeholder="Please Select" name="FD_Financials_year_end_date" #FD_Financials_year_end_date="ngModel"
[(ngModel)]="objCompanyFinancialDetails.FD_Financials_year_end_date" class="form-control">
<mat-option *ngFor="let date of FinancialYearEndDate" [(value)]="date.id">
{{date.value}}
</mat-option>
</mat-select>
TS TS
FinancialYearEndDate = [
{ id: "01", value: "01" },
{ id: "02", value: "02" },
{ id: "03", value: "03" },
{ id: "04", value: "04" },
{ id: "05", value: "05" },
{ id: "06", value: "06" },
{ id: "07", value: "07" },
{ id: "08", value: "08" },
{ id: "09", value: "09" },
{ id: "10", value: "10" },
{ id: "11", value: "11" },
{ id: "12", value: "12" },
{ id: "13", value: "13" },
{ id: "14", value: "14" },
{ id: "15", value: "15" },
{ id: "16", value: "16" },
{ id: "17", value: "17" },
{ id: "18", value: "18" },
{ id: "19", value: "19" },
{ id: "20", value: "20" },
{ id: "21", value: "21" },
{ id: "22", value: "22" },
{ id: "23", value: "23" },
{ id: "24", value: "24" },
{ id: "25", value: "25" },
{ id: "26", value: "26" },
{ id: "27", value: "27" },
{ id: "28", value: "28" },
{ id: "29", value: "29" },
{ id: "30", value: "30" },
{ id: "31", value: "31" }
];
You May want to check if the value you're trying to bind to your select , in this case "objCompanyFinancialDetails.FD_Financials_year_end_date", is present in the possible values of your options 您可能想检查一下您试图绑定到select的值 (在本例中为“ objCompanyFinancialDetails.FD_Financials_year_end_date”)是否存在于选项的可能值中
You may also want to replace your mat select component by a simpler definition: 您可能还想用更简单的定义替换垫选择组件:
<mat-select [(value)]='selectedDate'>
<mat-option></mat-option>
</mat-select>
You should bind same property to [(ngModel)]
and [(value)]
. 您应该将相同的属性绑定到[(ngModel)]
和[(value)]
。 In your case, [(ngModel)]
is complete object of date and [(value)]
is id of that object. 在您的情况下, [(ngModel)]
是日期的完整对象, [(value)]
是该对象的ID。 Code should be as below 代码应如下
<mat-select placeholder="Please Select" name="FD_Financials_year_end_date" #FD_Financials_year_end_date="ngModel"[(ngModel)]="objCompanyFinancialDetails.FD_Financials_year_end_date.id" class="form-control">
<mat-option *ngFor="let date of FinancialYearEndDate" [value]="date.id">
{{date.value}}
</mat-option>
</mat-select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.