Ng-zorro-antd: Click event for nz-card - nzActions

Created on 21 Dec 2018  ·  7Comments  ·  Source: NG-ZORRO/ng-zorro-antd

What problem does this feature solve?

I created a nz-card with nzActions using ng-template. In the example in ngzorro's web site we are only able to set click event to icon or nz-avatar. Some icons or avatars are a little bit small and user are not able to click properly. Is it possible to set click event to whole nzActions area.
(ng-template creates 'li' automatically so it would be great to set a function to ng-template so to li indirectly.)

What does the proposed API look like?


Card Content








Most helpful comment

I have a template solution, you can modified the style of the nz-card-action,make the tag li is contained the width and height, here is a demo.

All 7 comments

I have a template solution, you can modified the style of the nz-card-action,make the tag li is contained the width and height, here is a demo.

@NearZXH Thanks for the demo, this is exactly what I'm looking for. ;) Thanks

@NearZXH How can I pass variables (context) into the templates so that it can be passed into the on click function?

Typically with ngTemplate you would define the let-context and then set the context when you call the template, with the nzActions (and other card template attributes) I am unable to work out how to pass the content to the template through the card.

@RyanEntrostat Have you solve the problem that how to pass the content? I'm facing the same problem..

@RyanEntrostat Have you solve the problem that how to pass the content? I'm facing the same problem..

a bad but useful idea is to look up its parent , as its source code looks like this ![image](https://user-images.githubusercontent.com/51185888/59344094-f2f35480-8d3f-11e9-87a1-e50249ac5612.png) i seems i can use tag-name **nz-card** i need to find parent's id so i go up with a loop, and here the ways i try: - a loop in html
<div *ngFor="let article of articles;index as index" nz-col [nzSpan]="8">
            <nz-card [nzTitle]="article.lastModifiedDate|date" [id]="article.id"
                     [nzActions]="[actionEdit,actionDelete]">
              <a style="text-decoration: none;color: black" [routerLink]="['/note',article.id,'view']">
                <p>{{article.content.substr(0, 60)}}</p>
              </a>
            </nz-card>
          </div>
- and a template in html ``` ```` - and a function in *.ts.file
  gotoEdit(e: MouseEvent) {
    let element = e.srcElement;
    while ('nz-card'.toUpperCase() !== element.tagName) {
      element = element.parentElement;
      console.log(element.tagName);
    }
    console.log(`element.getAttribute('id') = ${element.getAttribute('id')}`);
  }
- it works well and prints ![image](https://user-images.githubusercontent.com/51185888/59344894-88dbaf00-8d41-11e9-8680-282e7f6b621c.png) hope it helps

it's absolutely a stupid way to do such thing, forget it
@RyanEntrostat @MAGICSCIENTIST

@RyanEntrostat @MAGICSCIENTIST @siweipancc
Because Ng-zorro doesn't provide the [ngTemplateOutletContext] in its code. so there is no good way to realize it.
But i'm confused that why do you need to do this, you can pass the variables in the function easily, i guess you have multiple nz-cards so you want to do different things to each one. Here is a stackblitz demo.

@RyanEntrostat @MAGICSCIENTIST @siweipancc
Because Ng-zorro doesn't provide the [ngTemplateOutletContext] in its code. so there is no good way to realize it.
But i'm confused that why do you need to do this, you can pass the variables in the function easily, i guess you have multiple nz-cards so you want to do different things to each one. Here is a stackblitz demo.

thanks for good solution.

btw: Maybe I have attentioned too much on #referrence that forget so much perspective, sad

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vthinkxie picture vthinkxie  ·  3Comments

Ximena-con picture Ximena-con  ·  3Comments

DoesntWong picture DoesntWong  ·  3Comments

IonelLupu picture IonelLupu  ·  3Comments

rafaelsmith picture rafaelsmith  ·  3Comments