I want to load a jquery script in Angular 4. In the html I have a table which display some data :
<table class="table">
<thead class="thead-inverse">
<tr>
<th>#</th>
<th>Hotel name</th>
<th>Price for night</th>
<th>Address</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let hotel of hotels">
<td>{{hotel.id}}</td>
<td>{{hotel.name}}</td>
<td>{{hotel.pricePerNight}}</td>
<td>{{hotel.address.city}}{{hotel.address.country}}</td>
</tr>
</tbody>
</table>
And I want to use a jquery script to allow me to change some data when I click in some td.
And this my component.ts :
@Component({
selector: 'hotel',
templateUrl: './hotel.component.html'
})
export class HotelComponent implements OnInit {
data: any;
constructor(){
this.getData((data) => {
this.data = data;
});
}
ngOnInit() { }
ngAfterViewInit() {
$('td').on('click', function() {
console.log("alooo");
var $this = $(this);
var $input = $('<input>', {
value: $this.text(),
type: 'text',
blur: function() {
$this.text(this.value);
},
keyup: function(e) {
if (e.which === 13) $input.blur();
}
}).appendTo( $this.empty() ).focus();
});
}
public getData(data) {
const req = new XMLHttpRequest();
req.open('GET', 'assets/data/listOfHotels.json');
req.onload = () => {
data(JSON.parse(req.response));
};
req.send();
}
}
The data displayed perfectly but when I click in any column I get nothing. (I made a simple code with and ... a static table, it works but in the dynamic version it doesn't work) Any help !