0

I have some template themes. and based on those themes, when I select any themes I want to change CSS file in the head, which has also the same name as the theme. I want to do it angular way.

Here are designList and update design function.->

$scope.designList = ['136', '140', '150', '139', '137', '086', '088', '104', '008', '106', '002'];
$scope.updateDesign = function (design) {
            $scope.websiteContent.globalPage.settings.template = design;
            angular.element("link#designID").attr("href", $scope.templateBasePath + "design/" + design + "/css/" + design + ".css");
};

Here is my design html->

<div>
    <h2 class="helvetica designSelect">Select Design</h2>
    <div id="selectThumbs" class="paging">
        <a href="#" class="design{{design}}" ng-repeat="design in designList">
            <img class="designthumb" ng-src="{{trustSrc(templateBasePath + 'design/thumbs/' + design + '.jpg')}}" ng-click="updateDesign(design)">
        </a>
    </div>
</div>

In index.html->

<link href="app/webapp/templates/design/136/css/136.css" rel="stylesheet" id="designID">

right now it's built using jquery but not working though. But I donot want to keep this. I want to use if there is any way using angular. Please help

1 Answer 1

2

You can use https://github.com/GabrielDelepine/angular-css-injector for this.

angular.module('myApp', ['angular.css.injector'])
.controller('myCtrl', ['cssInjector', '$scope', function(cssInjector, $scope) {
  cssInjector.add("style.css");

  $scope.changeCss = function () {
    cssInjector.removeAll();
    cssInjector.add("style1.css");
  }
}])

plnkr: http://plnkr.co/edit/2nNzQD7zKGCBSAltrrV4?p=preview

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

10 Comments

is there a bower package of this injector?
It didnot work. I followed readme.md but I saw nothing was added in head. cssInjector.add($scope.templateBasePath + "design/" + design + "/css/" + design + ".css");
i modified answer with a plnkr
Thank you for helping. Actually I need something that will change template css file reference in head. When a new theme is selected, css file for that theme (theme name and css file name are same) will be added in place of previous file.
So you can use cssInjector.removeAll(); to remove added css files and then add new
|

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.