Skip to content Skip to sidebar Skip to footer

Fetching Data From Query String

I'm trying to fetch data from this URL:https://api.chucknorris.io/jokes/search?query=chuck (chuck is the search term, it can be anything else). I want to get the value property fro

Solution 1:

// Modify your myService class :

searchJokes(str: string){returnthis.http.get('https://api.chucknorris.io/jokes/search?query=' + str)
                        .map(res => res.json())
                        .map(joke => {return joke.value});
    }

// and component :

searchJoke: string;
    searchRes: any[]=[];

    constructor(private searchService: PretragaService){

    }
    searchJokes(){
       this.searchService.searchJokes(this.searchJoke)
       .subscribe(joke => {
       this.searchRes = joke;
    });

Post a Comment for "Fetching Data From Query String"