简体   繁体   中英

How to add custom icon to Angular2 primeng Tree

I am creating tree using Primeng p-tree in my application and I need to add custom icons to tree nodes as shown in below JSON data. But tree node is not showing icons. If anyone has any idea please help me to resolve this issue.

{
            "label": "Pictures",
            "data": "Pictures Folder",
            "icon": "CustIcon.png",
            "children": [
                {"label": "Pic1", "icon": "icon1.png"},
                {"label": "Pic2", "icon": "icon2.png"},
                {"label": "Pic3", "icon": "icon3.png"}]
        }

I solved this problem using a template:

<p-tree [value]="equipmentLibrary" selectionMode="single">
    <template let-node pTemplate type="default">
        <span><img class="tree-icon" src="{{node.icon}}" /></span>
    </template>
</p-tree>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM