How to Get User Agent in Angular?

By Hardik Savani May 2, 2024 Category : Angular

Today, i would like to show you how to get user agent in angular application. we can simply get user agent in angular 8 application. we can get system user agent using window.navigator.

we can easily get user agent in angular 6, angular 7, angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, angular 14, angular 15, angular 16 and angular 17 application.

Sometime, we need to get user agent value for storing information to our server. so if you want to get user agent value then you can use jquery code variable like window. using window function we can get user agent value in angular application.

You can see bellow full example step by step.

You can see component file code for getting user agent value in angular app.

Component File Code

import { Component, OnInit } from '@angular/core';

@Component({

selector: 'app-blog',

templateUrl: './blog.component.html',

styleUrls: ['./blog.component.css']

})

export class BlogComponent implements OnInit {

constructor() { }

ngOnInit() {

const userAgent = window.navigator.userAgent;

console.log(userAgent);

}

}

Output

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36

I hope it can help you...

Shares