p-multiSelect选项标签是数据绑定的。你可以检查例子here。
如果要为标签添加更多文本,需要将它们添加到绑定到p-multiSelect选项的数组的对象的label属性中。
例子:
TS:
import { Component, OnInit, EventEmitter, Pipe, ChangeDetectorRef, Input } from "@angular/core";
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
@Component({
selector: 'input-overview-example',
templateUrl: 'input-overview-example.html',
styleUrls:['input-overview-example.css']
})
export class InputOverviewExample {
cars: SelectItem[];
selectedCars: string[] = [];
constructor() {
this.cars = [];
this.cars.push({label: 'Custom Label 1 Audi', value: 'Audi'});
this.cars.push({label: 'Custom Label 2 BMW', value: 'BMW'});
this.cars.push({label: 'Custom Label 3 Fiat', value: 'Fiat'});
this.cars.push({label: 'Custom Label 4 Ford', value: 'Ford'});
this.cars.push({label: 'Honda', value: 'Honda'});
this.cars.push({label: 'Jaguar', value: 'Jaguar'});
this.cars.push({label: 'Mercedes', value: 'Mercedes'});
this.cars.push({label: 'Renault', value: 'Renault'});
this.cars.push({label: 'VW', value: 'VW'});
this.cars.push({label: 'Volvo', value: 'Volvo'});
}
}
HTML:
<p-multiSelect [options]="cars" [(ngModel)]="selectedCars"></p-multiSelect>
<p>Selected Cars: {{selectedCars}}</p>
Plunker example
以上回答正确的,但有一些问题与解释正确的问题。谢谢 –