0

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 ?

2
  • 2
    what is 'add "something" to the else of the div' ? Commented Aug 18, 2017 at 11:38
  • 1
    Do you want to add attribute on double click? Commented Aug 18, 2017 at 11:39

1 Answer 1

2

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.something]="show ? true : null" (dblclick)="show=!show">Double click me to see the change</div>

Plunker

Sign up to request clarification or add additional context in comments.

8 Comments

Thats not what the OP is looking for I guess
I think he is looking to add an attribute to the same div
This way we always have something attribute with '' or ` : Hey !` value
I want to motivate you:) But @max2020 should provide more information about his problem
Thanks. It looks great.[attr.something]="show ? '' : null" seems that what he is expecting
|