asynchronoustypescriptxmlhttprequestangularjsonp

How to make a simple JSONP asynchronous request in Angular 2?


I'm trying to convert the following Angular 1 code to Angular 2:

$http.jsonp('https://accounts.google.com/logout');

It needs to be a JSONP request to skip the CORS policy issue.


Solution

  • With Angular 15's standalone component API, use withJsonpSupport():

    bootstrapApplication(AppComponent, {
      providers: [provideHttpClient(withJsonpSupport())],
    });