Angular Material Autocomplete force selection

后端 未结 6 1459
情书的邮戳
情书的邮戳 2021-02-07 09:18

In my angular 5 application I have some matAutocomplete, but I want to force the selection of oone of suggestions, so I am following this approach: stackblitz but for some reas

6条回答
  •  闹比i
    闹比i (楼主)
    2021-02-07 10:22

    maybe I'm late, but I fount this https://onthecode.co.uk/force-selection-angular-material-autocomplete/ Really simple solution based on validator:

    export function RequireMatch(control: AbstractControl) {
        const selection: any = control.value;
        if (typeof selection === 'string') {
            return { incorrect: true };
        }
        return null;
    }
    

提交回复
热议问题