Giter VIP home page Giter VIP logo

angular-css's Introduction

AngularCSS

CSS on-demand for AngularJS

Optimize the presentation layer of your single-page apps by dynamically injecting stylesheets as needed.

AngularCSS listens for route (or states) change events, adds the CSS defined on the current route and removes the CSS from the previous route. It also works with directives in the same fashion with the compile and scope destroy events. See the code samples below for more details.

Read the Article

Introducing AngularCSS: CSS On-Demand for AngularJS

Demos

Angular's ngRoute Demo (source)

UI Router Demo (source)

Quick Start

Install and manage with Bower or jspm. A CDN is also provided by cdnjs.com

$ bower install angular-css
$ jspm install github:castillo-io/angular-css
  1. Include the required JavaScript libraries in your index.html (ngRoute and UI Router are optional).
<script src="/libs/angularjs/1.5.6/angular.min.js"></script>
<script src="/libs/angularjs/1.5.6/angular-routes.min.js"></script>
<script src="/libs/angular-css/angular-css.min.js"></script>
  1. Add angularCSS as a dependency for your app.
var myApp = angular.module('myApp', ['ngRoute','angularCSS']);

NOTE: The module name "door3.css" is now deprecated.

Examples

This module can be used by adding a css property in your routes values, directives or by calling the $css service methods from controllers and services.

The css property supports a string, an array of strings, object notation or an array of objects.

See examples below for more information.

In Components

myApp.component('myComponent', {
  css: 'my-component/my-component.css' // <--- magic!
  templateUrl: 'my-component/my-component.html',
});

In Directives

myApp.directive('myDirective', function () {
  return {
    restrict: 'E',
    templateUrl: 'my-directive/my-directive.html',
    /* Binding css to directives */
    css: 'my-directive/my-directive.css'
  }
});

In Controllers

myApp.controller('pageCtrl', function ($scope, $css) {

  // Binds stylesheet(s) to scope create/destroy events (recommended over add/remove)
  $css.bind({ 
    href: 'my-page/my-page.css'
  }, $scope);

  // Simply add stylesheet(s)
  $css.add('my-page/my-page.css');

  // Simply remove stylesheet(s)
  $css.remove(['my-page/my-page.css','my-page/my-page2.css']);

  // Remove all stylesheets
  $css.removeAll();

});

For Routes (Angular's ngRoute)

Requires ngRoute as a dependency

myApp.config(function($routeProvider) {

  $routeProvider
    .when('/page1', {
      templateUrl: 'page1/page1.html',
      controller: 'page1Ctrl',
      /* Now you can bind css to routes */
      css: 'page1/page1.css'
    })
    .when('/page2', {
      templateUrl: 'page2/page2.html',
      controller: 'page2Ctrl',
      /* You can also enable features like bust cache, persist and preload */
      css: {
        href: 'page2/page2.css',
        bustCache: true
      }
    })
    .when('/page3', {
      templateUrl: 'page3/page3.html',
      controller: 'page3Ctrl',
      /* This is how you can include multiple stylesheets */
      css: ['page3/page3.css','page3/page3-2.css']
    })
    .when('/page4', {
      templateUrl: 'page4/page4.html',
      controller: 'page4Ctrl',
      css: [
        {
          href: 'page4/page4.css',
          persist: true
        }, {
          href: 'page4/page4.mobile.css',
          /* Media Query support via window.matchMedia API
           * This will only add the stylesheet if the breakpoint matches */
          media: 'screen and (max-width : 768px)'
        }, {
          href: 'page4/page4.print.css',
          media: 'print'
        }
      ]
    });

});

For States (UI Router)

Requires ui.router as a dependency

myApp.config(function($stateProvider) {

  $stateProvider
    .state('page1', {
      url: '/page1',
      templateUrl: 'page1/page1.html',
      css: 'page1/page1.css'
    })
    .state('page2', {
      url: '/page2',
      templateUrl: 'page2/page2.html',
      css: {
        href: 'page2/page2.css',
        preload: true,
        persist: true
      }
    })
    .state('page3', {
      url: '/page3',
      templateUrl: 'page3/page3.html',
      css: ['page3/page3.css','page3/page3-2.css'],
      views: {
        'state1': {
          templateUrl: 'page3/states/page3-state1.html',
          css: 'page3/states/page3-state1.css'
        },
        'state2': {
          templateUrl: 'page3/states/page3-state2.html',
          css: ['page3/states/page3-state2.css']
        },
        'state3': {
          templateUrl: 'page3/states/page3-state3.html',
          css: {
            href: 'page3/states/page3-state3.css'
          }
        }
      }
    })
    .state('page4', {
      url: '/page4',
      templateUrl: 'page4/page4.html',
      views: {
        'state1': {
          templateUrl: 'states/page4/page4-state1.html',
          css: 'states/page4/page4-state1.css'
        },
        'state2': {
          templateUrl: 'states/page4/page4-state2.html',
          css: ['states/page4/page4-state2.css']
        },
        'state3': {
          templateUrl: 'states/page4/page4-state3.html',
          css: {
            href: 'states/page4/page4-state3.css'
          }
        }
      },
      css: [
        {
          href: 'page4/page4.css',
        }, {
          href: 'page4/page4.mobile.css',
          media: 'screen and (max-width : 768px)'
        }, {
          href: 'page4/page4.print.css',
          media: 'print'
        }
      ]
    });

});

Responsive Design

AngularCSS supports "smart media queries". This means that stylesheets with media queries will be only added when the breakpoint matches. This will significantly optimize the load time of your apps.

$routeProvider
  .when('/my-page', {
    templateUrl: 'my-page/my-page.html',
    css: [
      {
        href: 'my-page/my-page.mobile.css',
        media: '(max-width: 480px)'
      }, {
        href: 'my-page/my-page.tablet.css',
        media: '(min-width: 768px) and (max-width: 1024px)'
      }, {
        href: 'my-page/my-page.desktop.css',
        media: '(min-width: 1224px)'
      }
    ]
  });

Even though you can use the media property to specify media queries, the best way to manage your breakpoints is by settings them in the provider's default settings. For example:

myApp.config(function($routeProvider, $cssProvider) {

  angular.extend($cssProvider.defaults, {
    breakpoints: {
      mobile: '(max-width: 480px)',
      tablet: '(min-width: 768px) and (max-width: 1024px)',
      desktop: '(min-width: 1224px)'
    }
  });

  $routeProvider
    .when('/my-page', {
      templateUrl: 'my-page/my-page.html',
      css: [
        {
          href: 'my-page/my-page.mobile.css',
          breakpoint: 'mobile'
        }, {
          href: 'my-page/my-page.tablet.css',
          breakpoint: 'tablet'
        }, {
          href: 'my-page/my-page.desktop.css',
          breakpoint: 'desktop'
        }
      ]
    });

});

Config

You can configure AngularCSS at the global or stylesheet level.

Configuring global options

These options are applied during your app's config phase or via $cssProvider.

myApp.config(function($cssProvider) {

  angular.extend($cssProvider.defaults, {
    container: 'head',
    method: 'append',
    persist: false,
    preload: false,
    bustCache: false
  });

});

Configuring CSS options

These options are applied at the stylesheet level.

css: {
  href: 'file-path.css',
  rel: 'stylesheet',
  type: 'text/css',
  media: false,
  persist: false,
  preload: false,
  bustCache: false,
  weight: 0
}

Support

AngularCSS is fully supported by AngularJS >= v1.3 && <= v1.5

There is partial support for AngularJS 1.2. It does not support css property via DDO (Directive Definition Object). The workaround is to bind (or add) the CSS in the directive's controller or link function via $css service.

myApp.directive('myDirective', function () {
  return {
    restrict: 'E',
    templateUrl: 'my-directive/my-directive.html',
    controller: function ($scope, $css) {
      $css.bind('my-directive/my-directive.css', $scope);
    }
  }
});

Angular 2

Can I use AngularCSS in Angular 2?

AngularCSS is not necessary in Angular 2! Angular 2 ships with a similar feature out of the box. It's called styles and styleUrls and it looks like this:

@Component({
  selector: 'my-component',
  templateUrl: 'app/components/my-component/my-component.html',
  styleUrls: ['app/components/my-component/my-component.css'],
})

Browsers

Chrome, Firefox, Safari, iOS Safari, Android and IE9+

IE9 Does not support matchMedia API. This means that in IE9, stylesheets with media queries will be added without checking if the breakpoint matches.

Contributing

Please submit all pull requests the against master branch. If your pull request contains JavaScript patches or features, you should include relevant unit tests.

Copyright and license

The MIT License

Copyright (c) 2017 Alex Castillo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

angular-css's People

Contributors

alexcastillo avatar camatangelo avatar diegozoracky avatar djmitchella avatar graundas avatar heston avatar megadesty avatar simonefalcini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-css's Issues

Its not working with state provider

Hi,

I added this in my angularjs app, used in a state.
In the state, provided the css.
But it is loaded in all of the (unrelated) states, instead of just the requisite state.

persist:true doesn't survive force reload

which is obvious
but then how to allow user to force reload?

so maybe you could add additional property which could mark that such css is general one
and has to be available for all pages
something like

{
   href: 'myGeneralCssFile.css',
   global: true
}

this will of course overwrite persist property and should probably also overwrite preload as well
EDIT:
just to explain - it would be useful for example for other libs css files
ie:
font-awesome

webpack

how in webpack use angular-css

Flash of un-styled content

Hi,
Your module is pretty awesome, however i have a little problem, while loading my page for the first time, i have a tiny moment when the css is not yet applied to the html so i can see all the html element without css.
My application is very simple: it has only one module named Homepage that load the homepage of the site.
-> I inject the homepage.css in the stateProvider in the config/homepage.js which is the first file to be load of the module Homepage.
-> In terms of timing the site takes about 550ms to completely load.
-> The homepage.css is load at about 450ms and the homepage.html is load at 550ms. So the css is load about 100ms before the html however i always have this moment without css.

Do you have any ideas how to fix this?
Thanks

Injection shows error due to and module name is 'door3.css' in 1.0.7

I install angular-css using bower and I got angular-css 1.0.7. The problem is the module name is door3.css rather then 'angularCSS'.

here is what I got.

/**
 * AngularCSS - CSS on-demand for AngularJS
 * @version v1.0.7
 * @author DOOR3, Alex Castillo
 * @link http://door3.github.io/angular-css
 * @license MIT License, http://www.opensource.org/licenses/MIT
 */

'use strict';

(function (angular) {

  /**
   * AngularCSS Module
   * Contains: config, constant, provider and run
   **/
  var angularCSS = angular.module('door3.css', []);

and here is new version in github

/**
 * AngularCSS - CSS on-demand for AngularJS
 * @version v1.0.8
 * @author Alex Castillo
 * @link http://castillo-io.github.io/angular-css
 * @license MIT License, http://www.opensource.org/licenses/MIT
 */

'use strict';

(function (angular) {

  /**
   * AngularCSS Module
   * Contains: config, constant, provider and run
   **/
  var angularCSS = angular.module('angularCSS', []);

should I use door3.css or wait for 'angularCSS'

css inheritance for child states for ui-router (non abstract)

Hi, is it possible to define nested states with ui-router and assign a stylesheet to a parent state that will be inherit for all child states?
Something like this:

  • profile: profile.css.
  • profile.about: about.css.
  • profile.friends: friends.css.

Where profile.about and profile.friends states both will not reload the profile.css file since it was already loaded for the profile state?
what I found happen is that only the child state style file is loaded!
is that the intended behaviour, or there's something I'm missing?
here's a plunker with examples, thanks in advance.

update:

when using the controller with the routes configurations the parent stylesheet gets loaded after the child stylesheet which ruin the overrides in the child state, this also happen when using only the controllers without the states configuration, also the link tags in the head gets inserted in the wrong order they should be reversed.

Error: [orderBy:notarray] Expected array but received: 0

Using Angular 1.5.0 and $routeProvider to inject the css like this:

.when('/profile/:memberId', { templateUrl: 'views/profile.html', controller: 'ProfileCtrl', css: { href: 'assets/css/profile.css', preload: true }, controllerAs: 'profile' })

Get an error that says: "Error: [orderBy:notarray] Expected array but received: 0"

Allow definition of breakpoints in $cssProvider.defaults

Allow definition of breakpoints in $cssProvider.defaults

This will allow the user to reference a breakpoint as opposed to be using the same media queries over and over.

The API should look like this:

myApp.config(function($routeProvider, $cssProvider) {

  angular.extend($cssProvider.defaults, {
    breakpoints: {
      mobile: '(max-width : 768px)',
      desktop: '(min-width : 769px) and (max-width : 1219px)',
      kiosk: '(min-width : 1220px)'
    }
  });

  $routeProvider
    .when('/black', {
      title: 'Black',
      templateUrl: 'pages/black/page-black.html',
      css: [
        {
          href: 'pages/black/page-black.mobile.css',
          breakpoint: 'mobile'
        }, {
          href: 'pages/black/page-black.desktop.css',
          breakpoint: 'desktop'
        }, {
          href: 'pages/black/page-black.kiosk.css',
          breakpoint: 'kiosk'
        }
      ]
    })

});

link.apply is not a function

2015-09-28 8 39 21

I added angular-css.js and
css included in directive works fine.
but "link.apply is not a function" error occured.

Can href be a folder destination?

Does this pulgin support folder destination? That is, on a parent state(Angular UI) set the href to folder and all the css files within the folder are added for child states of the parent state.

Dynamic CSS URL

Currently I am using a dynamic template URL using a function as given below in the Routes.

.when('/:page', {
    templateUrl : function(url) {
        return '/static/partials/' + url.page + '/template.html';
    },
    ....
}

When I tried the same with CSS, it is unable to find "url"

css : function(url) {
    return '/static/partials/' + url.page + '/styles.css'; 
}

Is there any chance that we can provide Dynamic CSS URL as mentioned above?

CSS Files getting called every time the view is loaded

I'm noticing that the css file attached to a view is getting called every time I go to its corresponding view. Is there a way to only load the css file the first time a view is loaded?

This issue is causing a delay between the time it takes to load the view and render the css which is very noticeable.

Is it compatible with ui router $stateParams?

Is it possible to return a string from a function to the css property in ui router? Because I would like to use the $stateParams to set the path to css file. Something like this:

.state('State', {
    url: '/page/:id',
    controller: 'Ctrl',
    templateUrl: function($stateParams){
        return $stateParams.id+'/views/index.html';
    },
    css: function($stateParams) {
        console.log($stateParams);
        return $stateParams.id+'/styles/main.css'
    }
});

directive link function arguments undefined

Anders: "Hey there Alex, first of all its a pretty damn cool plugin - just what I need for my project.. However once i set the css property in a directive, my link function is called with no arguments. So scope, and element are both undefined.
Is there a fix for this?"

Does this support abtract states for ui-router ?

Hi there,

I was wanting a way to include a certain CSS file (which is dynamic) on each and every state. I was thinking of doing this via an abstract state and having all other states use the abstract.

Does this support abstract states?

The css I need to include on every page would be available in a variable but I just can't insert it onto the page as it changes depending on certain this.

Is there support for this ?

got problem in IE9

I've tried this in my project, but unfortunately, it will throw "invalid arguments" error in IE9.
I do some analysis and want to confirm my guess:

  1. I use jquery 1.11.3
  2. I use angularjs 1.4.7
  3. I use angular-ui-router v0.2.15

I config the css like this:

 $stateProvider.state('home', {
      url: '/home',
      template: require('./views/home.html'),
      css: 'assets/home.css'
    })

the error occurred when jquery try to set href for the link dom element. I guess it happens when the template is compiled.(below code is from $set method in angularjs)

this.$$element.attr(attrName, value);

at this moment, attrName is 'href', value is 'assets/home.css'. then I debug into jquery, then the error will throw at this line in jquery:

elem.setAttribute( name, value + "" );

then I found this: http://stackoverflow.com/questions/1184950/dynamically-loading-css-stylesheet-doesnt-work-on-ie

it seems this link explain why the error happen in IE9. I guess it's because in angular-css, the template is compile first and then append to head, but it seems IE9 doesn't support this.

But angular-css's doc says it support IE9, So I'm doubt my analysis and just want to confirm it. and figure out why I get the error here.
Hope get some help from your guys :), thanks in advance.

Doesn't work if dependencies are defined on a directive.

If I want to a service or constant available as a dependency on the directive, it fails. Looking at the demo, this works:

myApp.directive('magenta', function () {
  return {
    restrict: 'E',
    replace: true,
    templateUrl: 'directives/magenta/directive-magenta.html',
    css: {
      href: 'directives/magenta/directive-magenta.css',
      /* Preload: this will trigger an HTTP request on app load.
       * Once the stylesheet is added, it will be loaded from the browser cache */
      preload: true
    }
  }
});

But this does not

myApp.directive('magenta', function ($log) {
    $log.debug("in magenta directive");
  return {
    restrict: 'E',
    replace: true,
    templateUrl: 'directives/magenta/directive-magenta.html',
    css: {
      href: 'directives/magenta/directive-magenta.css',
      /* Preload: this will trigger an HTTP request on app load.
       * Once the stylesheet is added, it will be loaded from the browser cache */
      preload: true
    }
  }
});

If I'm understanding the way this works, the directive factory is executed once in angular-cs.js to find the css definition and add appropriate event handlers.
var directive = angular.copy(originalDirectiveFactory)();
And when this fails, it is silently ignored (since many directives dont have css and might be written such that they might fail).:

However, this ignores the dependencies required by the factory. It looks like as long as the factory, itself, doesn't access the dependencies, or guards for undefined, and can return an object that has at least the the css def, it should work. In my case, I had a $log.debug that failed, because the $log is undefined, but was also using a constant to defined part of the path to the css and template.

Do you think it would it be feasible to use the $injector, so that the factory can execute properly as it would in normal use?

Delayed link when declaring css on a directive

Given a directive with a template that has a select with ngOptions, the presence of a css parameter seems to delay the link state of a directive such that ngOptions are parsed and set after a significant delay. This means that the ngModel value set on a directive isn't respected since there aren't
any values in the dropdown to compare against.

I've reproduced the issue in this Plunker: http://plnkr.co/edit/mDelhZqXeqhkTt55u51M

Angular 1.3.17 and angular-css 1.0.7

[request] When loading stylesheet with ui-router, hide view until stylesheet loads

With sufficiently large stylesheets, there is a noticeable flicker when loading the sheet; after the HTML renders, but before the CSS is applied. Angular and uiRouter both have solutions for this issue, but angular-css doesn't support either of them natively.

ngCloak does wait until the HTML renders, but the stylesheet lags behind considerably; and I can't find a way to use angular-css inside ui-router's resolve. Support for either of these would be fantastic. Personally, I think the ngCloak approach is more "Angular", but there needs to be a way to wait for the stylesheet before showing the page.

Thank you so much for an otherwise amazing project! This feels like one of those things that are so obvious it's weird they're not built into Angular as it is. Keep up the good work! ๐Ÿ˜

Stack overflow in big application with many modules/directives

We have a big AngularJS application and using angular-css extensively, since it gives a lot of freedom while designing directive templates.

When the application gets too big, FireFox and later also Internet Explorer begin to throw errors:

  • FF 40.0.3 says: Error: too much recursion
  • IE 11.0.9600.18015 says: Error: Out of stack space

Chrome is still happy with the app, until it grows even larger.

It seems that the problem lies in the call of $provide.decorator(...) in the "AngularJS hack" (lines 567+).

Plunker of an abstracted structure of our app (which leads to the errors in FF and IE): http://plnkr.co/XGIJzZPcHhkXQ3HUoLgG

Running unit tests

I'm about to submit a feature enhancement, but I'm not quite sure how the testing is setup. I've tried this:

npm install
bower install
grunt test

Am I doing something wrong or is the project not setup for unit testing yet?

Embed CSS without file

Is there a way to specify the CSS to inject as a set of rules in text format? I mean, without having to reference a CSS file?

Release 1.0.8

Hi,

Angular 1.5.0 has been released. Please release angular-css 1.0.8, as long as master contains the angular 1.5 compatibility fix.

$logProvider.debugEnabled false is overridden by app module

When the angular-css module is included in an app, the module's $logProvider.debugEnabled setting is overridden by the parent app's setting as it seems impossible to make the angular-css module have a distinct config phase. This makes for a significant amount of console noise.

Can the debugging be disabled in a way that leaves debugging enabled for the parent app? Perhaps remove the debug lines entirely as part of the build process, building to a dist folder?

Or am I seeing some weird behaviour that nobody else is seeing?

I'm using Angular 1.4.5

$css.preload may call the callback function too early

Hi there,

I was reviewing this promising angular module and found a small algorithm issue in the $css.preload() function.

Here's the original function code:

/**
 * Preload: preloads css via http request
 **/
$css.preload = function (stylesheets, callback) {
  // If no stylesheets provided, then preload all
  if (!stylesheets) {
    stylesheets = [];
    // Add all stylesheets from custom directives to array
    if ($directives.length) Array.prototype.push.apply(stylesheets, $directives);
    // Add all stylesheets from ngRoute to array
    if ($injector.has('$route')) Array.prototype.push.apply(stylesheets, $css.getFromRoutes($injector.get('$route').routes));
    // Add all stylesheets from UI Router to array
    if ($injector.has('$state')) Array.prototype.push.apply(stylesheets, $css.getFromStates($injector.get('$state').get()));
  }
  stylesheets = filterBy(stylesheets, 'preload');
  angular.forEach(stylesheets, function(stylesheet, index) {
    // Preload via ajax request
    $http.get(stylesheet.href)
      .success(function (response) {
        $log.debug('preload response: ' + response);
        if (stylesheets.length === (index + 1) && angular.isFunction(callback)) 
          callback(stylesheets);
      })
      .error(function (response) {
        $log.error('Incorrect path for ' + stylesheet.href);
      });
  });
};

I can see that angular.forEach(stylesheets, ... will make the program download each stylesheet by ajax, and for each stylesheet download success, we'll run the callback function only when we downloaded the last stylesheet in the list.

For me, the problem is that we assumed that stylesheets will be loaded in sequential order.
However, due to the nature of ajax requests and the unpredictable response speed of servers, this cannot be guaranteed.

So I think this part of the algorithm should take advantage of promises to make sure that the callback function is called at the end when all stylesheets have been loaded successfully.

So here's my suggested code change:

// Assuming that $q is injected in the module's JS scope

var stylesheetLoadPromises = [];
angular.forEach(stylesheets, function(stylesheet) {
  stylesheetLoadPromises.push(
    // Preload via ajax request
    $http.get(stylesheet.href)
      .success(function (response) {
        $log.debug('preload response: ' + response);
        if (stylesheets.length === (index + 1) && angular.isFunction(callback)) 
          callback(stylesheets);
      })
      .error(function (response) {
        $log.error('Incorrect path for ' + stylesheet.href);
      })
  );
});

if (angular.isFunction(callback)) {
  $q.all(stylesheetLoadPromises).then(function(){
    callback(stylesheets);
  });
}

Please let me know what you think.

Regards,

David

Best way to "switch" 2 or more css libraries/files potentially colliding used in 2 states/routes ?

Let's say I have 2 parts of a bigger website that typically look a lot different from the main website, ...like totally different and using totally different CSS assets (for historical reasons, etc.). When loading those 2 parts, I dont want them to "overwrite" neither any style from -a) the main site itself; & -b) nor each other.

Just to be sure, the way to deal with this is indeed with help from this cool plugin to specifically load the css needed WHEN I arrive on this $state (ui-router) and (also?) unload any "main" css files from the main websiite potentially colliding with the new css ...and when leaving to "reload" the "old" css from the main files and "unload" the css from $state I was on ? (And repeat same thing for the second 'special' part from my exampe)

Am I correct ? Thanks a lot.

CSS does not get used when $templateCache is used

Love the plugin but when I went to use this in my deployed version none of the CSS is loading. This looks to be down to the fact that my server version uses $templateCache for all html files and as these aren't loaded over html they are not picking up the new styles. Is there any workaround for this?

Component property not working

If I add the "css" property to a component it won't work:

image

Adding it to the UI router state works fine though:

image

It should work the first way according to the examples, any idea what's wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.