我有一个使用Typescript 2.0的角度2应用程序,我需要从typescript中将datetime参数传递给我的web api控制器。
但由于它将默认日期传递给控制器
,因此无法正常工作这是我的角度控制器代码
this.profileService
.getAvailableConsultant(this.ignoreList,currentUser.providerId,new Date(),1)
.subscribe(result => {
}));
我的角色服务
import { Injectable, Inject } from '@angular/core';
import { Http, Headers, Response } from "@angular/http";
import { APP_CONFIG, IAppConfig } from '../app.config';
@Injectable()
export class ProfileService {
apiURL: string;
constructor(public http: Http, @Inject(APP_CONFIG) private config: IAppConfig) {
this.apiURL = config.apiEndpoint;
}
getAvailableConsultant(ignoreList: string, providerId: number, currDate: Date, mode: number) {
var url: string = this.apiURL + "UserProfile/GetAvailableConsultant?" +
"ignoreList=" + ignoreList +
"&providerId=" + providerId +
"&currdate=" + currDate +
"&mode=" + mode
;
return this.http.get(url);
}
}
这是Web Api控制器代码
[HttpGet]
[Route("GetAvailableConsultant")]
public UserProfileDto GetAvailableConsultant(string ignoreList, int providerId,DateTime currdate,int mode)
{
return _profileService.GetAvailableConsultant(ignoreList,providerId, currdate,mode);
}
通过
1/1/0001 12:00:00 AM
作为控制器的currDate
答案 0 :(得分:0)
这将为您提供帮助。它将支持所有TS
像这样的通过日期 currDate.toISOString()
import { Injectable, Inject } from '@angular/core';
import { Http, Headers, Response } from "@angular/http";
import { APP_CONFIG, IAppConfig } from '../app.config';
@Injectable()
export class ProfileService {
apiURL: string;
constructor(public http: Http, @Inject(APP_CONFIG) private config: IAppConfig) {
this.apiURL = config.apiEndpoint;
}
getAvailableConsultant(ignoreList: string, providerId: number, currDate: Date, mode: number) {
var url: string = this.apiURL + "UserProfile/GetAvailableConsultant?" +
"ignoreList=" + ignoreList +
"&providerId=" + providerId +
"&currdate=" + currDate.toISOString() +
"&mode=" + mode
;
return this.http.get(url);
}
}