Search code examples
javascriptangularjsjqlite

How to change body style using angular


I have the following code and a bunch of other angular code :-

<body class="ftb2">

a lot of code here
</body>

and in the angular controller i have

var bodyTemp = $document[0].body;
                bodyTemp.removeClass("ftb2");

it gets the bodytemp but does not remove the class. From the chrome debugger :-

bodyTemp: body.ftb2
aLink: ""

etc....

Not sure what is the reason?

PS:- My angualar scope is defined inside a div within the body and i cannot change that so my code is like :-

<body class="ftb2">
<!-- angular boot strapped with this id-->
<div id="xyz">
</div>
</body>

bootstrap code :-

var root = document.getElementById("xyz");

 angular.bootstrap(root, ["appInvest"])

Solution

  • Its bad way of doing this, since there is no option to do it you need to add some DOM manipulation from controller.

    angular.element($document).find('body').removeClass('ftb2')
    

    Working Plunkr