I want to implement AJAX in Angular 2, but I don't now how to do this.
I have my Angular 2 component:
import { Component, OnInit, AfterViewInit } from '@angular/core';
declare var filter: any;
declare var pageLoaded: any;
@Component({
moduleId: module.id,
selector: 'Summary',
templateUrl: '/app/summary-view/summary.component.html',
styleUrls: [
'./summary.component.css',
]
})
export class Summary implements AfterViewInit {
ngAfterViewInit() {
pageLoaded();
filter();
}
}
In a Javascript file I have the function pageLoaded, this function includes an AJAX Call:
function pageLoaded() {
function fillFormattedDates(dates) {
var optionsd = "";
for (var i = 0; i < dates.length; i++) {
if (i == 0) {
optionsd += `<option id=${dates[i]} value=${dates[i]} selected>${formatDate(dates[i])}</option>`;
} else {
optionsd += `<option id=${dates[i]} value=${dates[i]}>${formatDate(dates[i])}</option>`;
}
}
document.getElementById('tableDates').innerHTML = optionsd;
}
$.ajax({
dataType: 'json',
url: `http://${host}${port}/api/v1/chart/c3/dates`,
type: "GET",
cache: false,
success: function(dates) {
fillFormattedDates(dates.data);
refreshTable();
}
});
}
How can I implement this AJAX call using Angular 2? I will really appreciate your help.
http
module? angular.io/docs/ts/latest/guide/server-communication.html – corn3lius 21 hours ago