-1

Here is my code I want to recall $('.ams-items').slimScroll() function

angular.element(document).ready(function () {
  $('.ams-items').slimScroll({
    alwaysVisible: true
  });
}); 

Please help me!

georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • Please read [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask). Your question does not conform with the community's guidelines, and will soon be closed by a moderator. You should edit it appropriately if you expect to get any answers. Good questions usually include: **A desired outcome or result**, **What you have tried so far to solve your problem** and more. – Soutzikevich Apr 29 '19 at 10:30

1 Answers1

1

How to Encapsulate jQuery code in a Custom Directive1

Any jQuery code that manipulates the DOM should be encapsulated in a custom directive so that it is executed when the AngularJS framework instantiates the element.

app.directive("mySlimScroll", function()
     return {
         link: postLink,
     };
     function postLink(scope,elem,attrs) {
         elem.slimScroll({
             alwaysVisible: true
         });
     }
});

Usage:

<div class="ams-items" my-slim-scroll>
</div>

To use jQuery, simply ensure it is loaded before the angular.js file.

For more information, see

georgeawg
  • 48,608
  • 13
  • 72
  • 95