尝试区分' xx01'时出错。只允许数组和可迭代

时间:2017-08-25 11:49:25

标签: angular primeng

假设我从API接收了一个字符串数组,例如[" xx01"," xx02"," xx03",..]。我应该在这做哪些更改,以便有一个正常工作的自动完成列表(primeng)。

我有此消息错误:错误错误:尝试区分' xx02'时出错。只允许数组和迭代

export class TaskComponent {

public sales: string[];
sale_A : string;
form: FormGroup;

constructor(private customer: CustomerService, private fb: FormBuilder, private router: Router) {
}

ngOnInit() {
    this.customer.getSales().subscribe(result => {
        this.sales = result;
        console.log(this.sales);
    });
    this.buildForm();
}

onSelectSale(event) {
    this.sales = event;
}

searchSales(event) {
    this.customer.getSales().subscribe(result => {
        this.sales = result;
    });
}

buildForm() {
    this.form = this.fb.group({
        sale_A: [{ value: ''}, Validators.required],
        sale_B: [{ value: '', disabled: true }, Validators.required]
    });
}

HTML:

<div class="col-md-5">
                <p-autoComplete formControlName="sale_A"
                                inputStyleClass="form-control"
                                [dropdown]="true"
                                [(ngModel)]="sales"
                                [suggestions]="sales"
                                (onDropdownClick)="searchSales($event)"
                                (completeMethod)="searchSales($event)"
                                (onSelect)="onSelectSale($event)"
                                emptyMessage="no msg">
                    <ng-template let-title pTemplate="item">
                        <p>{{sales[0] | json}}</p>
                    </ng-template>
                </p-autoComplete>
            </div>

0 个答案:

没有答案