NG-ZORRO / ng-zorro-antd

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

如何动态的创建Card组件的Actions #8580

Open jaune162 opened 1 month ago

jaune162 commented 1 month ago

What problem does this feature solve?

我使用Card组件展示待办消息,不同的待办消息操作也不同,如审批类有“审批”操作,业务类有“去处理”操作,我需要在使用的过程中动态的去创建Card组件的Action。

但是Card组件提供的actions属性接收的是一个TemplateRef数组。我无法通过编程式的方式来创建这个TemplateRef数组。

我定义了单个按钮的模板

<ng-template #action let-name="name" let-url="url">
  <a [routerLink]="url" *ngIf="url" >{{ name }}</a>
  <a *ngIf="!url" >{{ name }}</a>
</ng-template>

这是我的数据

actions: [
  {name: '审批', url: '/contract/audit?serviceId=xxxxxx'},
  {name: '详情', url: '/contract/details/xxxxxx'}
]

接下来我该怎么做呢?

What does the proposed API look like?

  1. 在文档中给出动态创建actions的方式
  2. 可以使用一个footer来覆盖actions,使得可以在footer中自定义卡片底部按钮
zorro-bot[bot] commented 1 month ago

Translation of this issue:

How to dynamically create a CARD component ACTIONS

What PROBLEM DOES This Feature Solve?

I use the CARD component to display the news to be handled, and different information operations are different. For example, the approval class has "approval" operation and the business class has "processing" operation. ACTION.

But the ACTIONS property provided by Card components receives a TemplateRef array. I can't create this TemplateEF array in a programming way.

I define the template of a single button

`html <ng-template #ACTION Let-name = "name" let-url = "url">> <a [routerlink ]="URL" *ngif="url"> {{name}} </a> <a *ngif=" !url"> {name}} </a> </ng-template> `

This is my data

`TS actions: [ {name: 'approval', url: '/contract/audit? Serviceid = xxxxxx'}, {name: 'Details', url: '/Contract/Details/xxxxxx'} ] `

What should I do next?

What does the proposed api look like?

  1. Give a dynamic way to create Actions in the documentation
  2. You can use a follower to cover Actions so that you can customize the bottom button at the bottom of the card in the foos