max2020 max2020 - 1 month ago 20
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:

HTML

<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:

HTML

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

Plunker