Skip to content

Service

Lorenzo D'Ianni edited this page Jul 13, 2017 · 1 revision

SidebarJSService

init(options: SidebarConfig): SidebarJS

Create a SidebarJS instance and return it. You should never call it.

open(sidebarName?: string): void

Open sidebar with the same name, if name is undefined the service will open the default sidebar

import { Component } from '@angular/core';
import { SidebarJSService } from 'ng-sidebarjs';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor(
    private sidebarjsService: SidebarJSService
  ) {}

  public openSidebar(sidebarName?: string): void {
    this.sidebarjsService.open(sidebarName);
  }
}
close(sidebarName?: string): void

Close sidebar with the same name, if name is undefined the service will close the default sidebar

import { Component } from '@angular/core';
import { SidebarJSService } from 'ng-sidebarjs';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor(
    private sidebarjsService: SidebarJSService
  ) {}

  public closeSidebar(sidebarName?: string): void {
    this.sidebarjsService.close(sidebarName);
  }
}
toggle(sidebarName?: string): void

Toggle sidebar with the same name, if name is undefined the service will toggle the default sidebar

import { Component } from '@angular/core';
import { SidebarJSService } from 'ng-sidebarjs';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor(
    private sidebarjsService: SidebarJSService
  ) {}

  public toggleSidebar(sidebarName?: string): void {
    this.sidebarjsService.toggle(sidebarName);
  }
}
isVisible(sidebarName?: string): boolean

Return true|false if the sidebar with the same name is visible, if name is undefined the service will check the default sidebar.

import { Component } from '@angular/core';
import { SidebarJSService } from 'ng-sidebarjs';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor(
    private sidebarjsService: SidebarJSService
  ) {}

  public isVisibleSidebar(sidebarName?: string): boolean {
    return this.sidebarjsService.isVisible(sidebarName);
  }
}
setPosition(position: 'left' | 'right', sidebarName?: string): void

Change the sidebar position, if name is undefined the service will change position of default sidebar

import { Component } from '@angular/core';
import { SidebarJSService } from 'ng-sidebarjs';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor(
    private sidebarjsService: SidebarJSService
  ) {}

  public setSidebarPosition(position: 'left'|'right', sidebarName?: string): void {
    this.sidebarjsService.setPosition(position, sidebarName);
  }
}
elemHasListener(elem: HTMLSidebarElement, value?: boolean): boolean

Return true|false if element has listenerFlag. Value argument will set explicitly the listenerFlag

import { Component } from '@angular/core';
import { SidebarJSService, HTMLSidebarElement } from 'ng-sidebarjs';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor(
    private sidebarjsService: SidebarJSService
  ) {}

  public hasSidebarListener(elem: HTMLSidebarElement, value?: boolean): boolean {
    return this.sidebarjsService.elemHasListener(elem)
  }
}
destroy(sidebarName?: string): void

Destroy the sidebar instance, if name is undefined the service will destroy the default sidebar. You should never call it.

Clone this wiki locally