Boris Parnikel Boris Parnikel - 2 months ago 4x
AngularJS Question

Add custom css rule with angular

I want to make an application with dynamic theming. For example, there is a button, you click it and color of some elements changes by some rule. First idea - do it with

<style type="text/css" ng-bind="ownStyle"></style>

and init ownStyle in $rootScope:

$rootScope.ownStyle = "* {color: green }";

But it seems awful + it's too hard to write css rules as string. Is there a more elegancy way to do it?


Can try something like this..

$rootScope.color = red;

$scope.changecolor = function(){
  $rootScope.color = blue;  
/* Base color */
  background-color: white;  
    background-color: {{$rootScope.color}} !important;

<button class="dinamic">I Will Change Color</button>