Changing body background color with angularjs

前端 未结 3 995
臣服心动
臣服心动 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:37

    I noticed that when I navigate to another page without page reload background color still remains, so I am doing this (I am using angular ui-router):

    In config:

    $stateProvider.state('app.login',{
                url: '/login',
                onExit: function($rootScope){
                    $rootScope.bodyClass = 'body-one';
                },
               templateUrl: 'ng/templates/auth/login-page-one.html',
                controller: function($rootScope){
                    $rootScope.bodyClass = 'body-two';
                }
            })
    
            .state('app.signup',{
                url: '/signup',
                onExit: function($rootScope){
                    $rootScope.bodyClass = 'body-one';
                },
                templateUrl: 'ng/templates/auth/signup-page-one.html',
                controller: function($rootScope){
                    $rootScope.bodyClass = 'body-two';
                }
            });
    

    In the Template

    
    

    In CSS:

    .body-one{
        margin-top: 50px;
        background: #f0f4fb;
    }
    
    .body-two{
        margin: 0;
        padding: 0;
        background: #2e9fff;
    }
    

提交回复
热议问题