我一直在寻找解决方案两天了。希望有人能帮助我。我是 Angular 5 的新手。

我正在尝试将 WP REST API 用于首页应用程序。遵循本教程后:

http://techattitude.com/tips-tricks-and-hacks/how-to-remotely-create-a-user-on-your-wordpress-website-using-json-api-request/

我发现有响应通过,但我无法访问该响应。我正在尝试 console.log() 响应值,但没有出现任何内容。下面是我的代码,请看一下,让我知道我做错了什么。我已经通过服务实现了我的 GET 请求。

api-config-nonce.ts

export interface ApiConfigNonce {
   status: String,
   controller: String,
   method: String,
   nonce: String 
}

授权服务.ts

import { EventEmitter, Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { ModalService } from '../services/modal.service';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operators';
import { ApiConfigNonce } from '../api-config-nonce';

@Injectable()
export class AuthService {
apiHost:string = 'http://localhost/';
apiBase:string = 'b0ffv3BH7K6h/';
email:string;
password:string;

userSignIn = new EventEmitter<object>();

constructor(private http:HttpClient, private modalService: 
ModalService){
}

login(email, password){


console.log('login()');
let options = {
    "insecure":"cool",
    "email":email,
    "password": password
}
    return this.http.post(this.apiHost + this.apiBase + 
'user/generate_auth_cookie/' , options);
}

getNonce(){
    return this.http.get<ApiConfigNonce>(this.apiHost + this.apiBase + 
'get_nonce/?controller=user&method=register')
    .map(res => res);
}

newUser(username, email, password, firstname, lastname, nonce){
    return this.http.get(this.apiHost + this.apiBase + 'user/register/? 
username='+ username + '&email=' + email + '&nonce=' + nonce + 
'&first_name=' + firstname + '&last_name=' + lastname);
}
}

注册.component.ts

import { Component, OnInit, AfterViewInit, ViewChild } from 
'@angular/core';
import { FormsModule } from '@angular/forms';
import { NgForm } from '@angular/forms';
import { UsersService } from '../../services/users.service';
import { AuthService } from '../../services/auth.service';
import { HttpClient } from '@angular/common/http';

@Component({
selector: 'app-sign-up',
templateUrl: './sign-up.component.html',
styleUrls: ['./sign-up.component.scss']
})
export class SignUpComponent implements OnInit, AfterViewInit {
@ViewChild('f') signupForm: NgForm;
signUpDetails:object;
busyProcessing:boolean = false;
errorMessage:string = null;
token:string = null;
userId:number = null;
nonce:any;


constructor(private usersService: UsersService, private authService: 
AuthService, private http:HttpClient) { }

ngOnInit() {
 this.getNonce();
}

ngAfterViewInit(){

}

getNonce(){
console.log('getNonce()');
this.authService.getNonce()
.subscribe(
  data => {
    this.nonce = JSON.stringify(data);
    console.log(data);
  },
  (error)=>{
    this.onError(error);
    console.log(error);
  }
);

console.log(this.nonce);
}


onError(response){
switch (response.error.code) {
case 406:
this.errorMessage = "Either that email or username is already in 
use";
break;
  case 403:
    this.errorMessage = "Failed to authorize, please try again later";
  default:
    this.errorMessage = "There was an error signing you up, please try 
 again";
    break;
}
this.busyProcessing = false;
}
}

我的组件中使用我的服务的函数是 getNonce()。我不确定为什么当我在邮递员上测试端点时我可以看到响应但无法将该响应分配给变量以使用它。它呈现此错误: “(未知 URL)的 Http 失败响应:0 未知错误”

任何帮助将不胜感激。