To load video content (e.g., video/mp4) using a GET request in Angular 4/5, you can use the HttpClient module to make the HTTP request to fetch the video file from the server. Then, you can display the video using the HTML5 video element. Here's a step-by-step guide on how to achieve this:

  1. Install Angular's HttpClient: Make sure you have the HttpClient module installed and imported in your Angular project. You can install it using npm:
npm install @angular/common@latest --save
  1. Import HttpClientModule in AppModule: In your app.module.ts, import HttpClientModule:
import { HttpClientModule } from '@angular/common/http'; @NgModule({ imports: [HttpClientModule], // ... other configurations ... }) export class AppModule { }
  1. Create a Component to Load Video:
import { Component } from '@angular/core'; import { HttpClient } from '@angular/common/http'; @Component({ selector: 'app-video-player', template: ` <video width="640" height="360" controls> <source [src]="videoUrl" type="video/mp4"> </video> ` }) export class VideoPlayerComponent { videoUrl: string; constructor(private http: HttpClient) { // Replace 'video.mp4' with the actual path to your video file on the server this.loadVideo('path/to/your/video.mp4'); } loadVideo(url: string) { this.http.get(url, { responseType: 'blob' }) .subscribe((response: Blob) => { // Create an object URL from the Blob data this.videoUrl = URL.createObjectURL(response); }); } }

In this example, we use the HttpClient's get method with { responseType: 'blob' } to fetch the video file as a Blob. Then, we create an object URL from the Blob data using URL.createObjectURL(response) and set it to the videoUrl property, which is bound to the src attribute of the source element in the template.

  1. Add the Component to AppModule:

Add the VideoPlayerComponent to your app.module.ts declarations:

import { VideoPlayerComponent } from './video-player.component'; @NgModule({ declarations: [VideoPlayerComponent], // ... other configurations ... }) export class AppModule { }
  1. Use the Component in your HTML:

Use the app-video-player element in your HTML to load the video:


Replace 'path/to/your/video.mp4' with the actual path to your video file on the server.

Now, when you run your Angular app, the video player component will load the video content from the specified URL using a GET request and display it using the video element with the appropriate MIME type.

Have questions or queries?
Get in Touch