• Home
  • Categories
  • Video Tutorials
    • Angular 5
  • News
  • About us
  • Contact us
  • Login
test
Code4Developers

Code4Developers

Code4Developers
  • Home
  • Categories
  • Video Tutorials
    • Angular 5
  • News
  • About us
  • Contact us
  • Login
  • AngularJs

Apply mCustomScrollbar using Angular Directive

  • Pawan Ingale
  • August 14, 2017
  • 2 minute read
AngularJs LOGO
Total
0
Shares
0
0
0

ngCustomScrollbar

Directives are very well-known in the world of angular developers. Every developer knows the power of a Directive. AngularJS has already provided many inbuilt directives which we are using on daily basis.

Why custom scroll bars are useful?

Browser default scroll bar are not so good to see while adjusting them with our web applications theme. So to remove that many of us takes the help of custom scroll bars. We all are familiar with the jQuery mCustomScrollbar.

Why we have created directive for custom scroll bar?

We all know that DOM manipulation in our controller file is a very bad habit while working with angular. That’s why we have created a directive for this so that we can avoid DOM manipulation.

Mandatory file list for using this directive?

Before using this directive one has to inject the below listed files in applications.

  • jQuery.js
  • jquery.mCustomScrollbar.js
  • jquery.mCustomScrollbar.css
  • mCSB_buttons.png
  • angular.js
  • ngCustomScrollbar.js (This is our directive file)

How to implement this directive in your web applications?

One needs to inject the module in their applications module app.

var myMCustomScrollBarDemo = angular.module('myMCustomScrollBarDemo', ['ngMCustomScrollBar']);

After following all of the above steps one can now use this directive as an attribute in application.

Below is the code by which one can declare the directive.

<body data-ng-app="myMCustomScrollBarDemo" data-ng-controller="controllername">

Using ng-m-custom-scroll

<div class="content" ng-m-custom-scroll>

By writing above code in your HTML one can see the custom scroll bar.

In this directive user can also set the properties for the custom scroll bar, For e.g.  like theme and other properties.

1) ng-scroll-config

In this attribute user can pass the angular object in this “ng-scroll-config” attribute by which this custom scroll bars properties can be applied.

<div class="content" ng-m-custom-scroll ng-scroll-config="configScroll" ng-custom-scroll-id="DivData1" ng-custom-scroll-class="">

OR

<div class="content" ng-m-custom-scroll ng-scroll-config="configScroll" ng-custom-scroll-id="" ng-custom-scroll-class="abc">

In Controller one has to set the properties like below

$scope.configScroll = { scrollButtons: { enable: false }, theme: "dark", live: "once" };

Using the above one can set the id/class in ng-custom-scroll-id/ng-custom-scroll-class  property on which one has to apply the custom scroll bar. Just like id one can pass the class name as well. If one wants to apply  this directive on custom id/class this option is useful. In above code the custom scroll bar will not apply on the div which contains the ng-m-custom-scroll attribute, but on that element which is written in the “ng-custom-scroll-id/ng-custom-scroll-class” option.

You can find this ngcustomscrollbar file in my GitHub account.

Pawan Ingale
Pawan Ingale

I am working as a Sr. Software Engineer, with hands on experience in AngularJS, C#, Web API Services, JavaScript, Highchart, D3 charts, Angular 2+.

Views: 6,686

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on X (Opens in new window) X
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to email a link to a friend (Opens in new window) Email
  • Click to print (Opens in new window) Print

Like this:

Like Loading...

Related Posts

Total
0
Shares
Share 0
Tweet 0
Pin it 0

Leave a ReplyCancel reply

Subscribe to Website via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Recent Posts
  • React Hooks Guide: Top Tips for Optimizing Performance in Your React Applications

    React Hooks Guide: Top Tips for Optimizing Performance in Your React Applications

    1 year ago
  • Demystifying JavaScript Tree Shaking: Boosting Performance and Reducing Bundle Size

    Demystifying JavaScript Tree Shaking: Boosting Performance and Reducing Bundle Size

    2 years ago
  • Unlocking the Power of React Hooks: A Comprehensive Guide with Examples

    Unlocking the Power of React Hooks: A Comprehensive Guide with Examples

    2 years ago
  • Celebrating a Decade of Phenomenal Growth: Insights and Reflections on 10 Years of Software Engineering

    Celebrating a Decade of Phenomenal Growth: Insights and Reflections on 10 Years of Software Engineering

    2 years ago
  • Angular Custom Elements: Creating Reusable Components with Angular

    Angular Custom Elements: Creating Reusable Components with Angular

    2 years ago
  • Connect Firebase Realtime NoSQL Database with Angular App from Scratch

    Connect Firebase Realtime NoSQL Database with Angular App from Scratch

    5 years ago
  • How to Build an Inclusive Esports Community

    How to Build an Inclusive Esports Community

    5 years ago
  • Best Digital Icebreakers

    Best Digital Icebreakers

    5 years ago
  • Email alerts when a docker container stopped in AWS ECS CLUSTER

    Email alerts when a docker container stopped in AWS ECS CLUSTER

    5 years ago
  • New Learning Models for Fall 2020

    New Learning Models for Fall 2020

    5 years ago
Subscribe to Website via Email

Enter your email address to subscribe to this website and receive notifications of new posts by email.

Featured Posts
  • javascript 1
    Spread syntax (three dots) in JavaScript
    • March 21, 2018
  • Angular 2
    Angular 6 CRUD – Part 1: Project Setup, Routing, Service
    • May 9, 2018
  • javascript 3
    Local Storage and Session Storage
    • May 22, 2017
  • Angular 4
    Angular 4 Project Structure
    • June 18, 2017
  • AWS 5
    Email alerts when a docker container stopped in AWS ECS CLUSTER
    • July 24, 2020
Code4Developers
Learning is never ending process

Input your search keywords and press Enter.

%d