0

I want to load css on demand but I don't get it.

This is the file structure

enter image description here

index.html

<script src="js/ui-router-styles.js"></script>
<script src="js/app.js"></script>
<script src="js/dao.js"></script>
<script src="js/controllers.js"></script>


....


</head>
  <body ng-app="starter" ui-router-styles>
    <div ui-view></div>
  </body>

app.js

var my_app = angular.module('starter', ['starter.posicion_integrada', 'uiRouterStyles','ionic','pascalprecht.translate']);

config part

my_app.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider) {

  $ionicConfigProvider.backButton.previousTitleText(false);
  $ionicConfigProvider.backButton.text('');

  $stateProvider
  .state('app', {
    url: '/app',
    abstract: true,
    templateUrl: 'views/menu.html',
    controller: 'appController'
  })

  .state('app.CarrouselSearcher', {
    url: '/CarrouselSearcher/:entUsuario/:codUsuario',
    views: {
      'menuContent': {
        templateUrl: 'views/carrouselSearcher.html',
        controller: 'carrouselsearcherCtrl',
        data: {
          css: ['css/tabla.css', 'css/carousel.css']
        }
      }
    }
  })
6
  • Have you got uiRouterStyles? Commented Feb 16, 2016 at 11:46
  • @SuperComupter I have updated the question. Commented Feb 16, 2016 at 14:28
  • did you tried to move ng app to html ? and plz show us your all app.js i mean config part Commented Feb 16, 2016 at 14:31
  • @SuperComupter is still failing, I've updated the question. Commented Feb 16, 2016 at 14:47
  • I think you forget to add angular-ui-router.js with this css noramlly loading with your state Commented Feb 16, 2016 at 16:30

1 Answer 1

0

I found a problem of your code in ui-router-styles.js

is

for(var state = toState; state && state.name !== ''; state=$$parentState(state)) {
          if(state && state.data && state.data.css) {
            if(!Array.isArray(state.data.css)) {
              state.data.css = [state.data.css];
            }

            angular.forEach(state.data.css, function(css) {
              // css = {name: 'layout', href: '/layout.css'}
              if(typeof css === 'object' && css.name && css.href && !stylesObject[css.name]) {
                stylesObject[css.name] = css.href;
              }else if(typeof css === 'string') {
                stylesObject[css] = css;
              }
            });

in your

.state('app.CarrouselSearcher', 

your data.css is in another object

state.current.views.menuContent.data.css;

// this condition checks just state.data.css

 if(state && state.data && state.data.css) {

your css are in views.menuContent then data.css

so this directive cant finds css from multiple views

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.