GithubHelp home page GithubHelp logo

agatakrajewska / ng2-device-detector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ahsanayaz/ngx-device-detector

0.0 2.0 0.0 11 KB

An Angular2 library to detect the device, OS and browser details

License: MIT License

TypeScript 100.00%

ng2-device-detector's Introduction

ng2-device-detector

An Angular 2 powered device detector that helps to identify browser, os and other useful information using user-agent using TypeScript (and ofcourse the compiled JS).

Device service

Holds the following properties

  • browser
  • os
  • device
  • userAgent
  • os_version

Installation

To install this library, run:

$ npm install ng2-device-detector --save

Usage

In your app.module.ts

import { NgModule } from '@angular/core';
import {Ng2DeviceDetector} from 'ng2-device-detector';
...
@NgModule({
  declarations: [
    // Components / Directives/ Pipes
    LoginComponent,
    SignupComponent
  ],
  imports: [
    CommonModule,
    FormsModule,
    Ng2DeviceDetector
  ],
  providers:[
    AuthService
  ]
  ...
})

In your component where you want to use the Device Service

import { Component } from '@angular/core';
...
import {Device} from 'ng2-device-detector';
...
@Component({
  selector: 'home',  // <home></home>
  providers: [
    ...
    Device,
    ...
  ],
  styleUrls: [ './home.component.scss' ],
  templateUrl: './home.component.html',
  ...
})

export class HomeComponent {
  ...
  constructor(..., private http: Http, private device: Device) {
    this.epicFunction();
  }
  ...
  epicFunction() {
    console.log('hello `Home` component');
    console.log(this.device);
  }
  ...
}

Development

To generate all *.js, *.js.map and *.d.ts files:

$ npm run tsc

To lint all *.ts files:

$ npm run lint

Credits

The library is inspired by and based on the work from ng-device-detector . Also used a typescript wrapper of the amazing work in ReTree for regex based needs and an Angular2 Library Creator boilerplate to get the work started fast. I.e. Generator Angular2 library.

License

MIT © Ahsan Ayaz

ng2-device-detector's People

Contributors

ahsanayaz avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.