gpt4 book ai didi

angular - @ViewChild ('tTaskTeam',{ 读取 : MatAutocompleteTrigger }) is not working after upgrading to V8

转载 作者:行者123 更新时间:2023-12-03 16:43:57 30 4
gpt4 key购买 nike

嗨,我今晚将我的项目从 V7 升级到 V8,我在阅读 @viewChild 时遇到了一堆错误,这是由于他们所做的新更新。我将 { static: true } 添加到我所有的 @viewChild,但后来我遇到了这些触发器,我设置如下:

 @ViewChild('tTaskTeam', { read: MatAutocompleteTrigger }) autoCompleteForTaskTeamTrigger: MatAutocompleteTrigger;
@ViewChild('tofficeUser', { read: MatAutocompleteTrigger }) officeUsersautoCompleteInputTrigger: MatAutocompleteTrigger;
@ViewChild('recipientType', { read: MatAutocompleteTrigger }) recipientTypeTrigger: MatAutocompleteTrigger;
viewChild只接受两个参数,我不能添加三个。所以我看了看: MatautocompleteTrigger出来了,它破坏了我的自动完成功能。

这是我收到的错误消息:

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.



我添加了这些触发器以在用户输入不是来自所选选项列表的字符时触发。所以它会清除并给用户一条消息让他们再次选择。

这是完整的实现:
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());
}

最佳答案

应该是

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

关于angular - @ViewChild ('tTaskTeam',{ 读取 : MatAutocompleteTrigger }) is not working after upgrading to V8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56624705/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com