Custom context in Angular Sidebar component
6 Sep 20223 minutes to read
Sidebar has a flexible option to make it initialize, target to any HTML element alongside of the main content of a web page.
By default, it initialize target to the body element. target
property allows users to set target element to initialize the Sidebar inside any HTML container element apart from the body element.
If required ,
zIndex
can be set when sidebar act as overlay type.
import { Component, ViewChild } from '@angular/core';
import { SidebarComponent } from '@syncfusion/ej2-angular-navigations';
import { ButtonComponent } from "@syncfusion/ej2-angular-buttons";
@Component({
selector: 'app-root',
styleUrls: ['app/app.component.css'],
templateUrl: 'app/app.component.html'
})
export class AppComponent {
@ViewChild('sidebar') sidebar: SidebarComponent;
public type: string = 'Push';
public target: string = '.content';
@ViewChild('togglebtn')
public togglebtn: ButtonComponent;
public onCreated(args: any) {
this.sidebar.element.style.visibility = '';
}
btnClick(){
if(this.togglebtn.element.classList.contains('e-active')){
this.togglebtn.content = 'Open';
this.sidebar.hide();
}
else{
this.togglebtn.content = 'Close';
this.sidebar.show();
}
}
closeClick() {
this.sidebar.hide();
this.togglebtn.element.classList.remove('e-active');
this.togglebtn.content = 'Open'
}
}
import { AppComponent } from './app.component';
import { ButtonModule } from '@syncfusion/ej2-angular-buttons';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { SidebarModule } from '@syncfusion/ej2-angular-navigations';
@NgModule({
imports: [SidebarModule, ButtonModule, BrowserModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);