DEV Community

Discussion on: Async material autocomplete in Angular

Collapse
 
federicopenaranda profile image
Federico Peñaranda

Practical and easy to follow code, thanks!. Question, what's the use of "!" in "this.form.get('name')!"?, I tried the code and I get an TSlint error "Forbidden non null assertion (no-non-null-assertion)", I understad that it might be to check if the field exists, but maybe we can do it in a different way to prevent that warning?. Cheers.

Collapse
 
tomwebwalker profile image
Tomasz Flis

Well, small hack could be:

    const nameControl = this.form.get('name') as AbstractControl
    this.countries$ = nameControl.valueChanges.pipe(
Enter fullscreen mode Exit fullscreen mode

But In this situation, I am telling code that I am sure about my name control because it is hardcoded.

Collapse
 
agborkowski profile image
AgBorkowski

just skip it, as linter saying its a mistake ;) I'm fighting with the loading spinner,
stackblitz.com/edit/angular-materi... but wont work with angular 10, and markDetectionChange :)