Why does the type change?

时间:2018-02-26 18:00:10

标签: angular

When i execute

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Car } from '../_models/car';
@Injectable()
export class UserCarsService {
constructor(private http: HttpClient) { }

getAll(params : any =  {params:{all:true}}) {
    return this.http.get<Car[]>('/api/user-cars', params);
}

}

getAll() returns <HttpEvent<Car[]>> type

but if i change this function to

getAll(params ={}) { return this.http.get<Car[]>('/api/user-cars', params); }

function will return Observable type. why this happens and how to fix it

error is caused in this function which resolves data before route:

`resolve(route:ActivatedRouteSnapshot, state:RouterStateSnapshot):Observable<Car[]> {
    return this.service.getAll({
        params : {
            id : Number(route['_urlSegment']['segments'][1]['path'])
        }
    );
    }`

0 个答案:

没有答案