Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I'm looking for the best way to manage the includes of css files,

I've found a great answer : http://stackoverflow.com/a/20404559/3163545 But this is working only with rootProvider.

So how to do something like this with stateProvider :

app.config(['$routeProvider', function($routeProvider){
    $routeProvider
        .when('/some/route/1', {
            templateUrl: 'partials/partial1.html', 
            controller: 'Partial1Ctrl',
            css: 'css/partial1.css'
        })
        .when('/some/route/2', {
            templateUrl: 'partials/partial2.html',
            controller: 'Partial2Ctrl'
        })
        .when('/some/route/3', {
            templateUrl: 'partials/partial3.html',
            controller: 'Partial3Ctrl',
            css: ['css/partial3_1.css','css/partial3_2.css']
        })
}]);

Thank you very much :)

share|improve this question
    
Keep in mind that it's generally best practice to combine and minify all your css files into one compact file that would only need to be downloaded once. This is greatly more performant than downloading many small files because each request has it's own overhead aside from just downloading the file. –  m59 Sep 8 '14 at 22:35

1 Answer 1

This module might help you: https://github.com/manuelmazzuola/angular-ui-router-styles

  1. Install it with Bower via bower install angular-ui-router-styles --save

  2. Ensure that your application module specifies uiRouterStyles as a dependency: angular.module('myApplication', ['uiRouterStyles'])

  3. Add css file(s) relative path to the state data object

.state('state1', { url: '/state', controller: 'StateCtrl', templateUrl: 'views/my-template.html', data: { css: 'styles/some-overrides.css' } })

share|improve this answer
    
will this work with JS files too? for example load a jquery file? –  user3362364 Jul 11 at 2:08
    
I think this module only works for stylessheets, not js. –  semeano Jul 12 at 21:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.