类型'Observable <boolean>'不可分配给类型错误。在Ang 5中无法在v6中工作

时间:2018-09-06 16:51:48

标签: angular5 angular6

将示例项目从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()

0 个答案:

没有答案