How to Get User Agent in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Angular Form Validation no Whitespace Allowed Example
- Angular Get Parameters from URL Route Example
- How to Get Query String from URL in Angular?
- Angular Http Post Request Example
- Angular Get Current Route Name Example
- Angular Font Awesome - How to install font awesome in Angular 9/8?
- How to Create Custom Validators in Angular 9/8?
- Reactive Form with Validation in Angular 8