如果条件不起作用,则为Angular HTTP POST方法

问题描述 投票:1回答:2

在角度7中,我在使用Http POST时遇到错误。但是当我尝试在if条件中使用该错误值时,if条件不会执行,否则总是会执行部分。

节点js(MEAN)的角度

errorParametre: any ;
this.http.post(`${this.uri}/compare`, {obj , err})
        .subscribe(res => {
           this.errorParametre = res['res']['err'].error;
           console.log(this.errorParametre);
           if (this.errorParametre === true) {
            console.log('hello');
            } else {
             console.log('irritating');
            }
           });
          }

console.log(this.errorParametre) => true,但如果条件也不能进去..只有false总是被执行

angular if-statement post methods condition
2个回答
0
投票

请处理这样的错误: -

this.http.post(`${this.uri}/compare`, {obj , err}).subscribe(
      response => {
          console.log('Successful');
      },
      err => {
          console.error("Error");
          this.errorParametre = true
      }
);

0
投票

您似乎正在接收错误值作为字符串,所以检查这样的条件

this.errorParametre === 'true'
© www.soinside.com 2019 - 2024. All rights reserved.