角垫选择

时间:2020-06-28 13:37:38

标签: angular typescript

当所选索引为0时,即“相同值”,我想传递0值而不是文本“相同值”。我们如何操纵数组来做到这一点?谢谢。

因为我需要在用户界面中显示“相同值”文本(请检查图像)作为选项,当用户选择它时,其值将为0

enter image description here

#HTML组件

<div fxFlex fxLayout="row">
          <mat-form-field appearance="outline" class="pr-4" fxFlex>
            <mat-label>Select Month</mat-label>
            <mat-select formControlName="month_" required>
              <mat-option *ngFor="let month of months;" [value]="month">
                {{month}}
              </mat-option>
            </mat-select>
          </mat-form-field>
        </div>

#TS组件

export class MonthSelectorComponent implements OnDestroy, OnInit {
  public months     = ["Same Value", 1, 2, 3, 6, 12];

.................

1 个答案:

答案 0 :(得分:0)

您需要拥有一个包含表示值和名称的对象的month数组。

因此,将您的月份数组更新为以下代码:

function updateWayPointsOnMap() {
    let options = {draggable: true};
    let wayPointIteration = 1;
    
    getRouteWayPoints().forEach(wayPoint => {
        let newMarker = L.marker([wayPoint.lat, wayPoint.lng], options).bindTooltip("Way point " + wayPointIteration).addTo(map)
            .on('move', function updateRoute(move) {
                getRouteWayPoints()[wayPointIteration - 1] = move.latlng;
                updateMap();
        });
        routeMarkers.push(newMarker);
        wayPointIteration ++;
    });
}

您的HTML代码应通过以下代码行进行更新:

 public months     = ["Same Value", 1, 2, 3, 6, 12];
  public months     = [{name:"Same Value",value:"0"},
                       {name:"1",value:"1"},
                       {name:"2",value:"2"},{name:"3",value:"3"},{name:"6",value:"6"}, {name:"12",value:"12"}];