我正在使用 mat-select 来显示下拉菜单,我需要在 angular 下拉菜单中选择所有功能。
下面是我的html
<mat-select formControlName="myControl" multiple (ngModelChange)="resetSelect($event, 'myControl')">
<mat-option>Select All</mat-option>
<mat-option [value]="1">Option 1</mat-option>
<mat-option [value]="2">Option 2</mat-option>
<mat-option [value]="3">Option 3</mat-option>
</mat-select>
Run Code Online (Sandbox Code Playgroud)
这是我的 ts 代码
/**
* click handler that resets a multiple select
* @param {Array} $event current value of the field
* @param {string} field name of the formControl in the formGroup
*/
protected resetSelect($event: string[], field: string) {
// when resetting the value, this method gets called again, so stop recursion if we have no values …Run Code Online (Sandbox Code Playgroud) 我已经使用Mat选择角度组件进行下拉,当我在下拉菜单(页面主体)之外单击时,需要触发一个事件。
<mat-select #select multiple (change)="onSubmit($event)" [(ngModel)]="emp">
<mat-option *ngFor="let value of filter.default" [value]="value">
{{value}}
</mat-option>
</mat-select>
Run Code Online (Sandbox Code Playgroud)
这是我的ts文件
export class AnotherComponent {
public text: String;
@HostListener('document:click', ['$event'])
clickout(event) {
if(this.eRef.nativeElement.contains(event.target)) {
console.log("clicked inside");
} else {
console.log("clicked outside");
}
}
constructor(private eRef: ElementRef) {
}
}
Run Code Online (Sandbox Code Playgroud)
它无法正常工作,请帮助