angular-loading-bar icon indicating copy to clipboard operation
angular-loading-bar copied to clipboard

Angular Material integration

Open matheusgrieger opened this issue 9 years ago • 5 comments

Is there a way to integrate angular-loading-bar with angular-material?

With the way the loading bar is currently created I couldn't make it work...

If not, is there a way to allow it?

matheusgrieger avatar Jun 09 '16 12:06 matheusgrieger

The problem is that the loadingBarTemplate template is not compiled. A little workaround is to manually trigger the compiler at runtime. You can use the cfpLoadingBar:started event for that.

angular
  .module('myApp', ['angular-loading-bar'])
  .config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {
    // set the material linear progress bar as template
    cfpLoadingBarProvider.loadingBarTemplate = '<md-progress-linear id="cfp-loading-bar" md-mode="indeterminate"></md-progress-linear>';
  }])
  .run(['$compile', '$window', '$rootScope', '$mdUtil', function($compile, $window, $rootScope, $mdUtil) {
    // wait for the element to be applied to the dom
    $mdUtil.nextTick(function () {
        // compile the element
        $compile(angular.element($window.document.getElementById('cfp-loading-bar')))($rootScope);
      });
  }]);

davidenke avatar Jun 15 '16 12:06 davidenke

I've tried your code, but it didn't work for me.

Can you provide a working plunker?

Thank you for your answer and time!

matheusgrieger avatar Jun 16 '16 02:06 matheusgrieger

Here is an example with an indeterminate linear progress bar.

davidenke avatar Jun 29 '16 11:06 davidenke

I don't understand why but this don't work in my project. The bar appear but still "empty" and no loading animation

CrunchyArtie avatar Sep 06 '16 13:09 CrunchyArtie

For anyone who might've struggled with this, I think the hint lies in @davidenke 's sentence:

You can use the cfpLoadingBar:started event for that.

It was left out of the code example (not sure why), so anyone copy/pasting that directly might have run into this. Also not sure why it seems to work without the event in some instances, but either way...

$rootScope.$on('cfpLoadingBar:started', event => {
  $mdUtil.nextTick( () => $compile(
    element(document.getElementById('loading-spinner'))
  )($rootScope) );
});

..is what got it working for me.

wosevision avatar Jan 24 '17 18:01 wosevision