Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make 2 ways data-binding for td in angular 2? [duplicate]

Tags:

angular

I need to use this editable column to display a "test" variable :

<td contentEditable="true" ngDefaultControl [(ngModel)]="test">{{test}}</td>

My td element displays the initial value of "test", but when I edit the td (using my keyboard), "test" does not change.

I have tested the same thing using input, and it works :

<input id="myinput" name="myinput" type="text" [(ngModel)]="test">

So what is the problem ?

like image 656
BrainabilGH Avatar asked Apr 21 '17 17:04

BrainabilGH


1 Answers

I tried this :

<td contentEditable="true" [textContent]="test" (input)="test=$event.target.textContent">{{test}}</td>

And it works.

like image 172
BrainabilGH Avatar answered Nov 13 '22 03:11

BrainabilGH