Cenk YAGMUR
Cenk YAGMUR

Reputation: 3451

Angular 5 Rxjs map return if condation

hi im trying but i can not, so i want get country name with function in google maps api

import {Injectable} from '@angular/core';
import {Observable} from "rxjs/Observable";
import 'rxjs/add/operator/map';

findMapData(results): string {
    return results.results[0].address_components.map(res => {
        return res.types[0] === 'country' ? res.short_name : "";
    });
}

this.findMapData(mapData);

I need just country name ?

Upvotes: 0

Views: 199

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222700

Use find instead

findMapData(results): string {
    return results.results[0].address_components.find(res => res.types[0] === country).short_name;
}

then

this.findMapData(mapData);

Upvotes: 1

Related Questions