尝试使用角材料在角2中实现简单的应用。
我用分页实现了一个简单的表。
我也使用了mat-select组件,但是为此,我想实现一个搜索过滤器来键入并从列表中搜索所需的选项。
<table>
<tr><td> Department</td>
<td>
<mat-form-field>
<mat-select placeholder=" ">
<mat-option> </mat-option>
<mat-option *ngFor="let dep of dept" [value]="dep">{{dep}}</mat-option>
</mat-select>
</mat-form-field><br/>
</td>
</tr>
</table>
<br><br>
<button >Search</button>
<button >Reset</button>
<button >Close</button>
<mat-card>
<div class="example-container mat-elevation-z8">
<mat-table #table [dataSource]="dataSource">
<!-- Account No. Column -->
<ng-container matColumnDef="accno">
<mat-header-cell *matHeaderCellDef> Account No. </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.accno}} </mat-cell>
</ng-container>
<!-- Account Description Column -->
<ng-container matColumnDef="accdesc">
<mat-header-cell *matHeaderCellDef> Account Description </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.accdesc}} </mat-cell>
</ng-container>
<!-- Investigator Column …Run Code Online (Sandbox Code Playgroud) 我使用了角度材料芯片控制,这一切都很好。但是,如果自动完成元素保持打开状态以便可以进行多个选择,那就太好了。在默认状态下,您必须将焦点移至不同的控件,然后再返回以重新打开自动完成。
是否可以设置一个选项来保持自动完成打开,直到用户完全远离控件?
<mat-form-field class="example-chip-list">
<mat-chip-list #chipList aria-label="Fruit selection">
<mat-chip
*ngFor="let fruit of fruits"
[selectable]="selectable"
[removable]="removable"
(removed)="remove(fruit)">
{{fruit}}
<mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
</mat-chip>
<input
placeholder="New fruit..."
#fruitInput
[formControl]="fruitCtrl"
[matAutocomplete]="auto"
[matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
[matChipInputAddOnBlur]="addOnBlur"
(matChipInputTokenEnd)="add($event)">
</mat-chip-list>
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
<mat-option *ngFor="let fruit of filteredFruits | async" [value]="fruit">
{{fruit}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
import {COMMA, ENTER} from '@angular/cdk/keycodes';
import {Component, ElementRef, ViewChild} from '@angular/core';
import {FormControl} from '@angular/forms';
import {MatAutocompleteSelectedEvent, MatAutocomplete} from '@angular/material/autocomplete';
import {MatChipInputEvent} from '@angular/material/chips';
import {Observable} from 'rxjs';
import {map, startWith} from 'rxjs/operators'; …Run Code Online (Sandbox Code Playgroud)