使用 primeng 和 angular 从所选项目中获取 p-dropdown 选项值
Getting p-dropdown option value from selected item with primeng and angular
我在尝试发送所选项目值时遇到问题,在遍历字符串数组时遇到问题,例如:("BMW", "FERRARI", "AUDI","BENTLY")
这是我的 HTML
<p-dropdown optionLabel="type" [options]="cars" formControlName="name"
editable="true" optionLabel="" optionValue="" (onChange)="loadCarsByName(name)">
</p-dropdown>
我的 loadCarsByName 方法中传递的值未定义任何想法都将受到欢迎。
尝试在标签和值中添加下拉值
carsNames =[
{label:'BMW', value:'BMW'},
{label:'FERRARI', value:'FERRARI'},
{label:'AUDI', value:'AUDI'},
];
或
carss: string[] = ['BMW', 'FERRARI', 'AUDI', 'BENTLEY'];
selectedPort="";
storeValue(event) {
console.log(event); //event.value will likely be undefined, check event.originalEvent
this.selectedPort = event.originalEvent.srcElement.innerText;
}
<p-dropdown [options]="cars" [(ngModel)]="selectedCity1" placeholder="Select a City" (onChange)="storeValue($event)">
<ng-template let-item pTemplate="selectedItem">
{{item}}
</ng-template>
<ng-template let-item pTemplate="item">
{{item}}
</ng-template>
</p-dropdown>
我在尝试发送所选项目值时遇到问题,在遍历字符串数组时遇到问题,例如:("BMW", "FERRARI", "AUDI","BENTLY")
这是我的 HTML
<p-dropdown optionLabel="type" [options]="cars" formControlName="name"
editable="true" optionLabel="" optionValue="" (onChange)="loadCarsByName(name)">
</p-dropdown>
我的 loadCarsByName 方法中传递的值未定义任何想法都将受到欢迎。
尝试在标签和值中添加下拉值
carsNames =[
{label:'BMW', value:'BMW'},
{label:'FERRARI', value:'FERRARI'},
{label:'AUDI', value:'AUDI'},
];
或
carss: string[] = ['BMW', 'FERRARI', 'AUDI', 'BENTLEY'];
selectedPort="";
storeValue(event) {
console.log(event); //event.value will likely be undefined, check event.originalEvent
this.selectedPort = event.originalEvent.srcElement.innerText;
}
<p-dropdown [options]="cars" [(ngModel)]="selectedCity1" placeholder="Select a City" (onChange)="storeValue($event)">
<ng-template let-item pTemplate="selectedItem">
{{item}}
</ng-template>
<ng-template let-item pTemplate="item">
{{item}}
</ng-template>
</p-dropdown>