代码之家  ›  专栏  ›  技术社区  ›  Rolando

如何全选?

  •  0
  • Rolando  · 技术社区  · 7 年前

    就“多选”而言:

    https://material.angular.io/components/select/overview

    HTML

    <mat-form-field>
      <mat-select placeholder="Toppings" [formControl]="toppings" multiple>
        <mat-option *ngFor="let topping of toppingList" [value]="topping">{{topping}}</mat-option>
      </mat-select>
    </mat-form-field>
    

    TS 从“@角度/核心”导入{组件}; 从“@角度/形状”导入{FormControl};

    /** @title Select with multiple selection */
    @Component({
      selector: 'select-multiple-example',
      templateUrl: 'select-multiple-example.html',
      styleUrls: ['select-multiple-example.css'],
    })
    export class SelectMultipleExample {
      toppings = new FormControl();
    
      toppingList = ['Extra cheese', 'Mushroom', 'Onion', 'Pepperoni', 'Sausage', 'Tomato'];
    }
    

    有没有办法“预先检查”像“额外奶酪”、“意大利香肠”这样的盒子?

    2 回复  |  直到 7 年前
        1
  •  2
  •   Patryk Gułaś    7 年前

    只需使用要在开始时检查的值数组定义浇头:

    toppings = new FormControl(['Extra cheese', 'Pepperoni']);
    
    toppingList = ['Extra cheese', 'Mushroom', 'Onion', 'Pepperoni', 'Sausage', 'Tomato'];
    
        2
  •  0
  •   Alexandr2134    7 年前

    尝试以下操作:

    toppingList=[“额外奶酪”、“蘑菇”、“洋葱”、“意大利香肠”、“香肠”、“番茄”];

    toppings=新表单控件(此.toppingList);