设置下拉角度2的默认值

时间:2017-05-02 01:24:11

标签: angular typescript

我在这里尝试过一些资源但从未像this那样工作过。我想将默认值设置为组件的下拉列表。我已经尝试使用Ngmodel将Select元素和Selected属性用于选项元素,但似乎无法正常工作

模板

<li *ngFor="let seats of quantityForView">
    <select (change)="ChangeTicketQuantity($event)" id="selectQuantityChange" [(ngModel)] ="seats.seatQuantitySelected">
        <option *ngFor="let ticketQuantity of seats.quantityList" [value]="ticketQuantity">
            {{ticketQuantity}}
        </option>
    </select>

组件

export class ChangeSeatQuantity  {
cartLineItems: any;
maxSeats: number;
selectedSeatQuantity: number;
quantityForView: any;

constructor(private _store: Store<any>) {
    this.cartLineItems = (<any>window).bootstrap.promoBoxViewModel.currentCart.cartLineItems;
    this.selectedSeatQuantity = this.cartLineItems[0].quantity;
    this.maxSeats = 10;
    this.SetQuantityForView();
}

SetQuantityForView()
{
    this.quantityForView = this.cartLineItems.map((seatsAvailable: any) => ({
        quantityList: Array(10).fill(1,1).map((x, i) => i),
        selectedSeatQuantity: this.cartLineItems[0].quantity
    }));
}
}

数据

this.quantityForView
[Object]
    0: Object
      quantityList: Array(10)
          1: 1
          2: 2
          3: 3
          4: 4
          5: 5
          6: 6
          7: 7
          8: 8
          9: 9
      length: 10
      __proto__: Array(0)
     selectedSeatQuantity: 2
     __proto__: Object
  length: 1
  __proto__: Array(0)

0 个答案:

没有答案