Changing body background color with angularjs

前端 未结 3 991
臣服心动
臣服心动 2020-12-15 13:26

I want to be able to change the background color of depending on what the current path is.

I tried doing it by checking $location.path() wh

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-15 13:36

    One way to style the body is to add ng-view as a body attribute, then use ng-class or ng-style (I did not use any other option to date).

    For example:

    
    
      
        My Site
        
      
      
        
      
    
    

    In this example, the login class is applied to the body only when loginBody is a true value in the current scope, set in a login controller.

    This is much less flexible than the approach offered by @ryeballar. It may just be enough in some cases.

提交回复
热议问题