2

Hi I have 3 languages on site, one of them has right-to-left letters, so when I change language I need dynamicly update css. Don't know how to do it. The problem is: I have ng-view, that has languages, where I change languages, and I have HeadController for whole document and when I change language inside ng-view, my Head controller don't see this changes. Here my index:

 <!doctype html> <html lang="en" ng-app="ow" ng-controller="HeadCtrl"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=100%, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"/> <title>OW</title> <link ng-repeat="stylesheet in stylesheets" ng-href="{{stylesheet.href}}" type="{{stylesheet.type}}" rel="stylesheet" /> <script src="lib/angular/angular.min.js"></script> <script src="lib/jquery-1.9.1.min.js"></script> <script src="js/main.js"></script> <script src="js/app.js"></script> <script src="js/controllers.js"></script> </head> <body class="fontMain"> <div ng-view></div> </body> </html> 

and app.js

angular.module('ow', []). config(['$routeProvider', function($routeProvider) { $routeProvider. when('/:placeId', {templateUrl: 'partials/menu.html', controller: MenuCtrl}). when('/menu/:itemId', {templateUrl: 'partials/menu-details.html', controller: MenuItemCtrl}). when('/look/refill', {templateUrl: 'partials/refill.html', controller: RefillCtrl}). when('/look/orderCart', {templateUrl: 'partials/orderCart.html', controller: OrderCartCtrl}). when('/lang/:lang', {templateUrl: 'partials/menu.html', controller: LangCtrl}). otherwise({redirectTo: '/0'}); }]).controller("HeadCtrl", function($scope, sharedData) { if (sharedData.getLang() == "he") { $scope.stylesheets = [ {href: "css/base.css", type: "text/css"}, {href: "css/right.css", type: "text/css"} ]; } else { $scope.stylesheets = [ {href: "css/base.css", type: "text/css"}, {href: "css/left.css", type: "text/css"} ]; } }); 

sharedData - contains shared values

and here Language controller:

 // Controller for language changes function LangCtrl($routeParams, $location, sharedData, $scope) { sharedData.setLang($routeParams.lang); $location.path("/"); } 
2
  • could you share complete code on fiddle or plunkerCommentedApr 30, 2013 at 17:17
  • there 4 big files for js, so I think, can't put all on fiddle, and also a few ajaxRequests on localhost, if you need something particular, I can give you it
    – Simcha
    CommentedApr 30, 2013 at 18:35

1 Answer 1

6

Have you taken a look at ng-class?

http://docs.angularjs.org/api/ng.directive:ngClass

More verbosely: I think you're going to be better off loading all of the css and then making a dynamic selection as to which you apply at runtime. Altering which files you're loading feels like the wrong approach to me.

One option: use ng-class to alter the class of the BODY tag on the fly, and have your rules match against elements occuring as children of a parent with either LEFT or RIGHT set.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.