【发布时间】:2018-04-18 12:00:10
【问题描述】:
我想获得 2 个变量。 1 表示当前日期 (yyyy-MM-DD),1 表示明天日期 (yyyy-MM-DD)。
我需要将这 2 个变量放在我的 HTTP 请求中。 有人可以告诉我如何制作 2 个变量并在我的 HTTP 请求中使用它们。 当前后面的代码是这样的:
export class BookingService {
private config: Object;
public today = new Date();
public tomorrow = new Date();
public domainSettings: Object = {};
constructor(
private http: Http,
private kioskservice: KioskService
) { }
public getAllBookings() {
return new Promise((resolve, reject) => {
this.http
.get(
`${this.kioskservice.getAPIUrl()}search/dashboard/${this.kioskservice.LocationGUID()}/?apikey=${this.kioskservice.getAPIKey()}&format=json&from=2018-04-17&until=2018-04-18&full=true`
)
.toPromise()
.then(
res => {
this.config = res.json()
console.log(res.json());
resolve();
},
msg => {
throw new Error("Couldn't get all Bookings: " + msg);
}
);
});
}
}
【问题讨论】:
-
你的两个问题都很基础,请先用google或搜索SO。日期:stackoverflow.com/questions/30397156/… 承诺示例:codecraft.tv/courses/angular/http/http-with-promises 或官方:angular.io/tutorial/toh-pt6
-
谢谢@Doomenik
标签: angular typescript