Search code examples
javascriptangularxmlhttprequest

How to show data through XMLHttpRequest() in Angular without using HttpClientModule?


Link to a demo of my Angular app

Here I connected a JSONPlaceholder (without using HttpClientModule) with my Angular app. When it renders the data is coming in browser console (using console.log() method), but I am not able to show this data in the HTML page. I tried using property by this method, but it is not coming.

Can anybody explain me how can I connect other API without using HttpClientModule in an Angular app?


Solution

  • You need to first declare and assign the data to get the result into view. Say declare in component :-

     data: any; 
    

    You need to parse the xml response result to Json and assign it.

    data = JSON.parse(this.responseText); 
    

    And for posting the json in UI use pipe json as :-

    <pre>{{data | json}}</pre>
    

    Have updated the bliz :- https://stackblitz.com/edit/httpclient-bhnusk?file=app%2Fapp.component.ts