[英]PrimeNG Angular 8 p-dropdown selectedItem template not rendering
Below is my markup for the custom template design for the PrimeNG p-dropdown control下面是我对 PrimeNG p-dropdown 控件的自定义模板设计的标记
<p-dropdown [options]="list" [(ngModel)]="selectedListItem" (onChange)="selectionChanged($event)">
<ng-template let-item pTemplate="selectedItem">
<div class="custom-template-div">
<div class="pull-left location-icon {{item.value.cssClass}}"></div>
<div class="header-line pull-left"><b>{{item.value.text1}}</b></div>
<div class="clearfix"></div>
<div class="detail-line"><i>{{item.value.text2}}</i></div>
</div>
</ng-template>
<ng-template let-item pTemplate="item">
<div class="custom-template-div">
<div class="pull-left location-icon {{item.cssClass}}"></div>
<div class="header-line pull-left"><b>{{item.text1}}</b></div>
<div class="clearfix"></div>
<div class="detail-line"><i>{{item.text2}}</i></div>
</div>
</ng-template>
</p-dropdown>
In this control the <ng-template let-item pTemplate="item">
section is working as expected when the dropdown is listing the items with CSS icons, but when an item been selected, it is not showing in the control, but in the code level the items is selected.在此控件中, <ng-template let-item pTemplate="item">
部分在下拉列表列出使用CSS ICONS的项目时,按预期工作,但是当该项目未在控件中显示,但在控件中没有显示时选择项目的代码级别。
I'm using a custom DTO as below;我正在使用如下的自定义 DTO;
export class ListItemDto {
text: string;
text1: string;
text2: string;
value: string;
cssClass: string;
}
I'm having issue only with the <ng-template let-item pTemplate="selectedItem">
template where as I have tried item.value
to get the object as well as directly item
also.我只对<ng-template let-item pTemplate="selectedItem">
模板有问题,因为我已经尝试过item.value
来获取 object 以及直接item
。 Both are not working for me.两者都不适合我。
Any information would be helpfull.任何信息都会有所帮助。 Thanks!谢谢!
My colleague found the issue and it is just to have the label
and value
properties available in whatever the custom DTO we use as the collection.我的同事发现了这个问题,它只是让label
和value
属性在我们用作集合的任何自定义 DTO 中都可用。 I only had value
property.我只有value
财产。
export class ListItemDto {
text: string;
text1: string;
text2: string;
label: string;
value: string;
cssClass: string;
}
If the custom DTO contains the properties label
and value
properties along with other custom properties, the selectedItem
template will start to work.如果自定义 DTO 包含属性label
和value
属性以及其他自定义属性,则selectedItem
模板将开始工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.