Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 尝试区分'时出错;xx01';。只允许使用数组和iterables_Angular_Primeng - Fatal编程技术网

Angular 尝试区分'时出错;xx01';。只允许使用数组和iterables

Angular 尝试区分'时出错;xx01';。只允许使用数组和iterables,angular,primeng,Angular,Primeng,假设我从一个API接收到一个字符串数组,如[“xx01”、“xx02”、“xx03”、…]。我应该在这里做哪些更改以使自动完成列表(priming)正常工作 我收到以下消息错误:错误:尝试区分'xx02'时出错。只允许使用数组和iterables export class TaskComponent { public sales: string[]; sale_A : string; form: FormGroup; constructor(private customer: Custome

假设我从一个API接收到一个字符串数组,如[“xx01”、“xx02”、“xx03”、…]。我应该在这里做哪些更改以使自动完成列表(priming)正常工作

我收到以下消息错误:错误:尝试区分'xx02'时出错。只允许使用数组和iterables

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:


{{sales[0]| json}


我认为如果您没有使用多选,您应该使用销售对象来存储所选销售
[(ngModel)]=“selectedSale”
-
[建议]=“sales”
我认为如果您没有使用多选,您应该使用销售对象来存储所选销售
[(ngModel)]=“selectedSale”
-
[建议]=“销售”
<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>