我对来自api的数据响应有问题,数据为空
此代码归档服务登录
@Injectable({
providedIn: 'root'
})
export class LoginService {
constructor( private http:HttpClient) { }
login(body) {
const headers=new HttpHeaders;
headers.append('content-Type', 'application/json'),
headers.append('api_key', '7zttgA4kFVsD2V2n0beMpzdLQRiSAKxtVEpyeW9MaEFEND0g')
headers.append('Access-Control-Allow-Origin','*')
headers.append('Access-Control-Allow-Methods','GET,POST')
headers.append('Access-Control-Allow-Headers','X-Requested-With ')
return this.http.post('https://bell.s2c.io/api/v1/Login', body,
{ headers: headers }).pipe(res=>res)
}}
代码login.ts
@Component({
selector: 'app-login',
templateUrl: './login.page.html',
styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {
private formlogin : FormGroup;
Device:any
ListDevices:any
constructor(private servicelogin:LoginService,private formBuilder: FormBuilder,private router : Router
)
{
this.formlogin = this.formBuilder.group({
username: ['', Validators.required],
password: ['',Validators.required],
});
}
logForm(){
this.servicelogin.login(this.formlogin.value).subscribe(data=>{
console.log(data)
})
}
ngOnInit() {
}
}
我使用console.log(data)进行测试以查看数据响应,但数据为空是什么问题?