max2020 max2020 - 7 months ago 54
TypeScript Question

Angular on doubleclick Div append to div

I am trying to find a way to add something inside a div when i double click it.

So I have a div:

<div>Double click here</div>

What I need to do with Angular is when I doubleclick on a div I need the code to add "something" to the else of the div.

For example...

Before I doubleclick I have:

<div>Double click here</div>

and after I doubleclick I need to have:

<div something>Double click here</div>

How can I do this in Angular 2 / 4 ?

Answer Source

I think you are looking for this:


<div *ngIf="show" (dblcick)="show=!show">You see the first div</div>
<div *ngIf="!show" (dblclick)="show=!show">You see the second div</div>

or if you are trying to add an attribute on a div:


<div [attr.somethingElse]="show ? true : null" (dblclick)="show=!show">Double click me to see the change</div>


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download