Home » RxJS ajax() Creation Operator

RxJS ajax() Creation Operator

by Online Tutorials Library

RxJS ajax() Creation Operator

RxJS ajax() operator is a creation operator used to create an observable for an Ajax request with either a request object with url, headers, etc. or a string for a URL.

In other words, we can say that the RxJS ajax() operator makes an ajax request for the given url. We have to first import the ajax to work with it.

Syntax:

Following is the syntax of the RxJS ajax() creation operator:

Or

Parameter Explanation

There is not any such parameter that we have to explain.

Let us see some examples of the RxJS ajax() operator to understand it clearly.

Example 1 (Observable that emits the response object that is being returned from the request)

Index.ts file:

Index.html file:

Output:

After executing the above example, you will see the following result:

RxJS ajax() Creation Operator

Example 2 (Observable that emits only the JSON key of the response object that is being returned from the request)

Index.ts:

Index.html:

Output:

After executing the above example, you will see the following result:

RxJS ajax() Creation Operator

Example 3 (Observable that emits the error object that is being returned from the request)

Output:

After executing the above example, you will see the following result:

RxJS ajax() Creation Operator

Example 4 (Ajax operator with object as input)

Output:

After executing the above example, you will see the following result:

RxJS ajax() Creation Operator


Next TopicRxJS Operators

You may also like