-1
Angular 2でAJAXを実装したいのですが、これを行う方法はありません。Javascript関数を使用してAngular 2でAJAXを実装する方法
私は私の角度2の成分があります。
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();
}
});
}
どのように使用して、このAJAX呼び出しを実装することができます:Javascriptのファイルで
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();
}
}
私はpageLoaded機能を持って、この関数はAJAXコールが含まれて角2?私は本当にあなたの助けに感謝します。
'http'モジュールを使用しますか? https://angular.io/docs/ts/latest/guide/server-communication.html – corn3lius