Angular参数不可分配(Httpclient)

时间:2019-04-17 15:47:43

标签: angular typescript

我正在使用“ @ angular / common”:“ ^ 6.0.7”,文档中说httclient.request可以接受字符串或HttpRequest。但是,当我传递HttpRequest时,出现错误TS2345:类型为'HttpRequest <{reportProgress:boolean;观察:字符串; }>'不能分配给'string'类型的参数。

下面是代码。

barrierDismissible: false,

谢谢。

解决方案

查看所使用的功能。就我而言

var dateStart = new DateTime(2019,01,10);
var dateEnd = new DateTime(2019,01,31);

var timeBetween = (dateEnd - dateStart).TotalDays + 1;
int numberOf7DayWeeks = (int)(timeBetween / 7);
int numberOfWeekendDays = numberOf7DayWeeks * 2;
int workingDays =(int)( timeBetween - numberOfWeekendDays);

if(dateStart.DayOfWeek == DayOfWeek.Saturday || dateEnd.DayOfWeek == DayOfWeek.Sunday){
    workingDays -=2;
}       
if(dateStart.DayOfWeek == DayOfWeek.Sunday || dateEnd.DayOfWeek == DayOfWeek.Saturday){
    workingDays -=1;
}

1 个答案:

答案 0 :(得分:0)

文档说您可以传递HttpRequest类型。因此,当您构造它时可以通过。

  const req = new HttpRequest('GET', url, {
      reportProgress: true
    });

    return this.http.request(req).pipe(
     map(event => this.getEventMessage(event, file)),
      retry(3),
      catchError(this.handleError));