@joshdoescode/browser-service v1.0.0
Browser Service
Angular 4 (CLI) Browser Service
Install
npm install @joshdoescode/browser-service
Add to your app.module
import { BrowserService } from '@joshdoescode/browser-service/src/browser.service';
@NgModule({
declarations: [
...
],
imports: [
...
],
providers: [
...
BrowserService
],
...
})
Usage
Use inside your component, or another service.
All methods for this service are static, so there is no need to inject it.
Import the service
import {BrowserService} from "@joshdoescode/browser-service/src/browser.service";
Call the service
let id = BrowserService.getQuerystringValue('id');
Methods
Cookie names and querystring parameter names are case sensitive.
getQuerystringValue( name: string, url: string ): string
Returns null if the parameter name cannot be found in the querystring. Returns an empty string if the parameter is in the querystring, but has no value (e.g. '.../?bookcase
'). Returns the value of the parameter, if one is set.
name
- Name of the parameter to search for the value of.
url
(optional) - The URL to analyse the querystring of. Default is the current URL.
setCookie( name: string, value: string, days: number )
Sets a cookie for the current domain called 'name
', with a value of 'value
', that will expire in 'days
' days.
getCookie( name: string ): string
Returns the value of the cookie called 'name
', or an empty string if one is not found.
removeCookie( name: string )
Removes a currently set cookie called 'name
'.