Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

p-autocomplete #7781


User avatar
0
sophoana created

Hi Support how to assign value and display text in p-autocomplete when edit second form. Cannot display text in p-autocomplete when edit second form.

I'm use: -angular 7 -asp.net core

Source code:

filteredChartOfAccount: NameValueOfString[];
chartOfAccount: any;

html:

<p-autoComplete
        id="SingleSelectInput"
        name="SingleSelectInput"
        field="name"
        [(ngModel)]="chartOfAccount" 
        [suggestions]="filteredChartOfAccount" 
        (completeMethod)="filterChartOfAccount($event)"
        [minLength]="1"
        inputStyleClass="form-control"
        styleClass="width-percent-100">
        <ng-template let-chartOfAccount pTemplate="item">
            {{chartOfAccount.name}}
        </ng-template>
    </p-autoComplete>

.ts:

// get filter
filterChartOfAccount(event): void {
    this._chartOfAccountServiceProxy.getChartOfAccountSelectItems(event.query)
    .subscribe(chartOfAccountResult => {
        this.filteredChartOfAccount = chartOfAccountResult;
    });
}

// single select - post
onSelectedChartOfAccounts(): void {
    let selectedChartOfAccounts = new Array<NameValueOfString>();
    selectedChartOfAccounts.push(this.chartOfAccount);
    this._chartOfAccountServiceProxy.sendAndGetSelectedChartOfAccounts(selectedChartOfAccounts)
        .subscribe((ChartAccount: NameValueOfString[]) => {              
            _.forEach(ChartAccount, item => {
                this.tax.vatOutChartOfAccountId = parseInt(item.value);
            });
        });
}

2 Answer(s)
  • User Avatar
    1
    musa.demir created

    This should work.

    this.chartOfAccount = new NameValueOfString({
        name: "DisplayName",
        value: "1"//value
    });
    
  • User Avatar
    0
    sophoana created

    Many thanks support teams @demirmusa