如何从角度6的服务中订阅,我收到未定义的错误

时间:2018-12-08 03:03:38

标签: json http rxjs angular6

这是我的服务,我正在使用angular 6软件包,Api响应正常,我正在获取json

for fullname in files(os.path.join(path, r"Training data\LOW")):
    base, ext = fullname.rsplit(".", 1)
    os.rename(fullname, base + "Low." + ext)

}

但是在ng服务上,组件函数给出了错误,该未定义变量在USER响应中成功,我在Angular 2,4,5中使用了相同的概念从未出错,我想知道为什么它的行为如此, 就像AOT构建一样,在ng serve上预编译代码

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { catchError, map, tap } from 'rxjs/operators';

const httpOptions = {
  headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};


@Injectable({
  providedIn: 'root'
})

export class LoginService {
  constructor(private http: HttpClient)
  {

  }

  login(value: any)
  {
    let body = JSON.stringify(value);
    return this.http.post('XXXXXXXXXXXXXXXX',body, httpOptions);
  }

我要附上终端的图片 enter image description here

1 个答案:

答案 0 :(得分:0)

请提及回复类型。如果您不知道响应类型,则使用    “任何”响应类型。但是,最好使用响应类型。

 submitForm(value: any)
    {
         // this.toasterService.pop('info',' Loading...', '' );
         this._loginservice.login(value).subscribe(
         (user:any) => {
         if(user.success) 
         {
         }
       });
    }