Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including kentico-cloud-angular-http-service with all npm packages installed. Try it out:

require("@angular/common/package.json"); // @angular/common is a peer dependency. require("@angular/core/package.json"); // @angular/core is a peer dependency. require("kentico-cloud-core/package.json"); // kentico-cloud-core is a peer dependency. require("rxjs/package.json"); // rxjs is a peer dependency. var kenticoCloudAngularHttpService = require("kentico-cloud-angular-http-service")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

kentico-cloud-angular-http-service v3.0.0

Implementation of IHttpService using Angular HttpClient

Angular Http service

This is an implementation of the IHttpService that can be used instead of the default http service available in Core package that uses axios package.

This library uses Angular's HttpClient to make http requests and can be used only in Angular applications.

Why and when should you use this library?

If you need to use server side rendering with prerender using Angular universal, you have to use Angular's built-in Http service because otherwise Angular will not wait until the requests are fetched from server and therefore your code would not be reflected in HTML of your page. You can find more information about the issue here

Example

First, you need to import AngularHttpServiceModule module into your AppModule (or other module depending on your architecture) and then you can inject AngularHttpService just as you are used to in Angular.

import { AngularHttpServiceModule } from 'kentico-cloud-angular-http-service';

@NgModule({
  imports: [
    AngularHttpServiceModule,
    // other imports
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

and example taken from a component:

  private readonly deliveryClient: IDeliveryClient;

  constructor(angularHttpService: AngularHttpService) {
    this.deliveryClient = new DeliveryClient({
      projectId: 'da5abe9f-fdad-4168-97cd-b3464be2ccb9',
      httpService: angularHttpService
    });
  }
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free