将示例项目从Angular 5升级到6。 https://github.com/mmacneil/AngularASPNETCore2WebApiAuth
该错误发生在return语句上。
Type 'Observable<boolean>' is not assignable to type 'Observable<UserRegistration>'.
注册功能
register(email: string, password: string, firstName: string, lastName: string, location: string, gender: string, birthDate: any): Observable<UserRegistration> {
let body = JSON.stringify({ email, password, firstName, lastName, location, gender, birthDate });
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.baseUrl + "/accounts", body, options)
.pipe(
map(res => true),
catchError(this.handleError)
);
}
UserRegistration
export interface UserRegistration {
email: string;
password: string;
firstName: string;
lastName: string;
location: string;
birthDate: any;
gender: string;
}
可能是我缺少一些新的导入吗??
显示导入。
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';
import { UserRegistration } from '../models/user.registration.interface';
import { ConfigService } from '../utils/config.service';
import { BaseService } from "./base.service";
import { Observable } from 'rxjs/Rx';
import { BehaviorSubject } from 'rxjs/Rx';
import { map, filter, catchError, mergeMap } from 'rxjs/operators';
// Add the RxJS Observable operators we need in this app.
import '../../rxjs-operators';
@Injectable()