Boris Parnikel Boris Parnikel - 1 year ago 91
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?

Answer Source

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>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download