Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@ViewChild('tTaskTeam', { read: MatAutocompleteTrigger }) is not working after upgrading to V8

Hi I upgraded my project from V7 to V8 tonight and I got a bunch of errors reading the @viewChild which was due to the new updates they did. I added { static: true } to all my @viewChild, but then I came across these triggers that I have setup up like this:

 @ViewChild('tTaskTeam', { read: MatAutocompleteTrigger }) autoCompleteForTaskTeamTrigger: MatAutocompleteTrigger;
  @ViewChild('tofficeUser', { read: MatAutocompleteTrigger }) officeUsersautoCompleteInputTrigger: MatAutocompleteTrigger;
  @ViewChild('recipientType', { read: MatAutocompleteTrigger })  recipientTypeTrigger: MatAutocompleteTrigger;

The viewChild only accepts two parameters and I can't add three. So I took read: MatautocompleteTrigger out and it broke my autocomplete function that I had going.

This is the error message I am getting :

Argument of type '{ read: typeof MatAutocompleteTrigger; }' is not assignable to parameter of type '{ read?: any; static: boolean; }'. Property 'static' is missing in type '{ read: typeof MatAutocompleteTrigger; }' but required in type '{ read?: any; static: boolean; }'.ts(2345) core.d.ts(8066, 9): 'static' is declared here.

I added these triggers to trigger if a user enters characters that aren't from the selected option list. So it will clear out and give the user a message to have them select again.

This is the full implementation: HTML

<mat-form-field appearance="outline" class="task-info-form-field">
  <input tab-directive #tTaskTeam matInput (keyup.enter)="chooseFirstOption(autoCompleteForTaskTeam)" [matAutocomplete]="autoCompleteForTaskTeam" formControlName="tTaskTeam" matTooltip="You can search and it will try to autocomplete the name for you!" placeholder="Select Group">
  <mat-autocomplete #autoCompleteForTaskTeam='matAutocomplete' [displayWith]="displayTeamName">
    <mat-option class="matAutoCompleteSelect" *ngFor="let user of filteredOptions | async" [value]="user">
      <span>{{ user.TeamName }}</span>
    </mat-option>
  </mat-autocomplete>
  <mat-error>
    Value entered is NOT VALID please selected only from suggested values.
  </mat-error>
</mat-form-field>

TS

@ViewChild(MatAutocomplete, {
  static: true
}) autoCompleteForTaskTeam: MatAutocomplete;

@ViewChild('tTaskTeam', {
  read: MatAutocompleteTrigger
}) autoCompleteForTaskTeamTrigger: MatAutocompleteTrigger;

subscriptionTeam: Subscription;

ngAfterViewInit() {
  this._subscribeToClosingActions();
  this._subscribeToClosingActionsThree();
  this._subscribeToClosingActionsTwo();
}

ngOnDestroy() {
  if (this.subscription && !this.subscription.closed) {
    this.subscription.unsubscribe();
  }
  if (this.subscriptionTeam && !this.subscriptionTeam.closed) {
    this.subscriptionTeam.unsubscribe();
  }
  if (this.subscriptionUser && !this.subscriptionUser.closed) {
    this.subscriptionUser.unsubscribe();
  }
}


private _subscribeToClosingActions(): void {
  if (this.subscriptionTeam && !this.subscriptionTeam.closed) {
    this.subscriptionTeam.unsubscribe();
  }

  this.subscriptionTeam = this.autoCompleteForTaskTeamTrigger.panelClosingActions
    .subscribe(e => {

        if (!e || !e.source) {
          this.form.controls.tTaskTeam.setValue('');
        }
      },
      err => this._subscribeToClosingActions(),
      () => this._subscribeToClosingActions());
}
like image 586
elquesogrand Avatar asked Jun 17 '19 04:06

elquesogrand


2 Answers

Should probably be

@ViewChild('tTaskTeam', { read: MatAutocompleteTrigger, static: false}) autoCompleteForTaskTeamTrigger: MatAutocompleteTrigger;

like image 84
GreyBeardedGeek Avatar answered Nov 16 '22 01:11

GreyBeardedGeek


i cannot comment so i have to add answer

https://v8.angular.io/guide/static-query-migration

like image 40
Damian Pioś Avatar answered Nov 16 '22 01:11

Damian Pioś