Run simple jQuery functions from controller/directive when there is no element

265
November 26, 2016, at 8:05 PM

I am using a jQuery plugin called Material-preloader which only requires including its css/js file, following by instantiating and calling its functions. No elements or classes are required and it magically appears during runtime at the top of the page (demo)

How would I go about calling the 'on' and 'off' functions from within my controller or directive? I'm not sure how that would work when I don't have any elements to work with. Therefore using ng-hide/ng-show/ng-if is not possible as there is nothing to attach them onto.

e.g.

function LoadingCtrl($scope, $rootScope, uiCalendarConfig, $timeout) {
    $rootScope.$on('pageLoaded', function() {
        // turn off the preloader here
    });
}

Instantiating it is as so:

<script type="text/javascript">
  //settings
 preloader = new $.materialPreloader({
        position: 'top',
        height: '5px',
        col_1: '#159756',
        col_2: '#da4733',
        col_3: '#3b78e7',
        col_4: '#fdba2c',
        fadeIn: 200,
        fadeOut: 200
    });
// turn it on
preloader.on();
// turn it off
 preloader.off();
</script>
Answer 1

Convert that jquery plugin as a directive and then you will have element access to it.

READ ALSO
a href slider(like image slider, but with links)

a href slider(like image slider, but with links)

I want do navigate trough my navigation with arrowsforwoard and backwoards and go back to the first at the last link and to the last at the first

281
Use a function inside an event both located inside an object and than invoke that

Use a function inside an event both located inside an object and than invoke that

Hello I am new at this object oriented javascript (or any oop for that matter) and I am trying out some things, and keep getting stuck at a point

167
Update function REST with Jquery

Update function REST with Jquery

Learning alot on how to use REST, currently I am able to create and delete items but can't get the update function to workI tried so many combinations but keep getting 400 bad requests errors stating that the data

274
Call php file and request certain variables/information then display in div

Call php file and request certain variables/information then display in div

The overall goal is to relay information from a mysql server via a php file to the webpage being viewedMore specifically I want to target certain aspects of the php file, or certain tables in the database, and display them in different divs on the webpage

200