Tom
Tom

Reputation: 8681

upgrade from angular 4 to 6 for http giving error map does not exists

I have upgraded from angular 4 to 6 and have changed the http library to httpClient. I am getting error with the http method saying map does not exist. Could somebody tell me what the problem is

export class LocalisationProxy {
    constructor(private _nghttp: HttpClient,
                private _phttp: ProxyHttp) { } 


    getLatestTranslationFilesAndMerge(cultureId: number): Observable<ApiResult<any>> {
        return this._nghttp.get(`/platform/localisation/${cultureId}`, null||{})
                    .map(ret => ({ data: ret.json(), originalResponse: ret}));
    }
}

Upvotes: 1

Views: 146

Answers (2)

Eduardo Vargas
Eduardo Vargas

Reputation: 9402

With rxjs 6 now is used pipable operators.

    import { map } from 'rxjs/operators'

    getLatestTranslationFilesAndMerge(cultureId: number): Observable<ApiResult<any>> {
         return this._nghttp.get(`/platform/localisation/${cultureId}`,null||{})
            .pipe(map((ret=>({ data: ret.json(), originalResponse: ret})));
        }
    }

Because you are using the httpClient by default it is converted to json so your map is unecessary.

getLatestTranslationFilesAndMerge(cultureId: number): Observable<Something> {
         return this._nghttp.get<Something>(`/platform/localisation/${cultureId}`);
        }
    }

Upvotes: 4

BlizZard
BlizZard

Reputation: 589

Please use RxJS-compact while upgrading to angular 6

just install rxjs-compat by typing in terminal:

npm install --save rxjs-compat

then import :

import 'rxjs/Rx';

Upvotes: 1

Related Questions