NG-ZORRO / ng-zorro-antd

Angular UI Component Library based on Ant Design
https://ng.ant.design
MIT License
8.85k stars 3.9k forks source link

当使用nzOptions方式使用nz-select时,templateRef如何自定义下拉option的内容,其内容根据数据项变化 #7793

Open woaiyan opened 1 year ago

woaiyan commented 1 year ago

Reproduction link

https://stackblitz.com/edit/ng-zorro-antd-ivy-scqx4c?file=src%2Fapp%2Fapp.component.ts

Steps to reproduce

https://stackblitz.com/edit/ng-zorro-antd-ivy-scqx4c?file=src%2Fapp%2Fapp.component.ts

What is expected?

可以通过nzOptions自定义下拉内容

What is actually happening?

可以通过nzOptions自定义下拉内容

Environment Info
ng-zorro-antd 11.4.1
Browser chrome
zorro-bot[bot] commented 1 year ago

Translation of this issue:

When using NZOPTIONS to use NZ-SELECT, TemplateRef

REPRODUCTION LINK

[https://stackblitz.com/edit/ng-zorro-Ntd- ivy-scqx4c?file=src%2FApp.com ivy-SCQX4C? File = src%2FAPP%2FAPP.COMPONENTS)

STEPS To Reproduce

https://stackblitz.com/edit/ng-zorro-Ntd- ivy-scqx4c?file=src%2FAPPP.CONENTS.TS

What is exfected?

You can customize the drop -down content through nzoptions

What is actually happy?

You can customize the drop -down content through nzoptions

ENVIRONMENT Info
NG-Zorro-ATD 11.4.1
Browser Chrome
Nicoss54 commented 1 year ago

Hey if i understand well your needs, you wan to display a custon template for the option of the select component. This is already possible :). The NzOptionComponent have the nzCustomContent. This properties accept a boolean.

If this properties is set to true, the content between the nz-option balise is used as the nzLabel value. If it's false nzLabel value is used. By default the nzCustomContent is set to false.

In your case, you want to use the nzOptions as an input and retrive the value in your custom template. This is not possible for the moment. As a wokaround you can use the first option with NzCustomContent