angular2 路由ajax,如何通过Javascript函数在Angular 2中实现AJAX
我有我的角2部分:
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();
}
}
JavaScript文件我具備的功能pageLoaded,該功能包括AJAX調(diào)用:
function pageLoaded() {
function fillFormattedDates(dates) {
var optionsd = "";
for (var i = 0; i < dates.length; i++) {
if (i == 0) {
optionsd += `${formatDate(dates[i])}`;
} else {
optionsd += `${formatDate(dates[i])}`;
}
}
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();
}
});
}
我如何使用實現(xiàn)這個AJAX調(diào)用Angular 2?我會很感激你的幫助。
+3
使用'http'模塊? https://angular.io/docs/ts/latest/guide/server-communication.html –
總結(jié)
以上是生活随笔為你收集整理的angular2 路由ajax,如何通过Javascript函数在Angular 2中实现AJAX的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 内网群PING的shell
- 下一篇: java美元兑换,(Java实现) 美元