What is the usefulness of pipe () and map () functions in Angular 6?

0

I learned that I have to use both of these functions when I'm working with Http requests, I've learned that you have to use both of these functions as a cake recipe, which you use and ready, I wanted to know why you should use it. >

Example of using both functions:

    public pesquisaOferta(termo: string): Observable<Oferta[]> {
    return this.http.get(URL_API + "?descricao_oferta_like=" + termo)
    .pipe(
        retry(10),
        map((response: any) => {
            return response
        })
    )
}

If I'm not mistaken, I've seen the use of the two functions in a different way, but I'm alluding to why I use them.

    
asked by anonymous 01.09.2018 / 17:19

1 answer

3

The pipe() function is used to read data from a source as it becomes available and write that data to another location.

For example, in your HTTP request example you make the request and the data is gradually arriving, as each piece of data arrives, it becomes available within the function pipe()

The map() function creates a new array with the array data it maps, iterating over each element. It is very used to perform actions according to each element.

In this answer of Stackoverflow, you can read more about some specific advantages of why you use these two functions.

    
01.09.2018 / 17:54