如何在 angular material 2 中下拉数量?

how to have a dropdown of quantities in angular material 2?

如何在 angular material 2 中显示数量下拉列表?

以下似乎不起作用:

 <md-list-item>
        <img md-list-avatar src="/images/shirt.jpg" alt="shirt">
        <h2 md-line> Shirt </h2>
        <p md-line> .80 </p>
        <md-select placeholder="Quantity">
            <md-option *ngFor="let q of quantities" [value]="q"> {{q}} </md-option>
        </md-select>
    </md-list-item>

在我的 ts 文件中

export class BuyComponent implements OnInit, OnDestroy
{
    quantities: [1,2,3,4,5,6,7,8,9,10];
        ...
}

它不起作用的原因是您错误地尝试为数组赋值 quantities。您需要使用 = 赋值。所以而不是

quantities: [1,2,3,4,5,6,7,8,9,10];

需要:

quantities = [1,2,3,4,5,6,7,8,9,10];

这似乎工作正常。

Demo