1

I want to hide the navBar when the route is "/"

I succeeded to hide/show the navbar but the problem is that, when the navbar is hidden, the "app-body" div has 50px of padding top (where should be the navbar)

This is my html code

<body ng-app="myApp"  ng-controller="MainController" ui-prevent-touchmove-defaults>

    <div class="app">
        <!-- Navbars -->
        <div ng-hide="isActive('/')" ng-controller="NavBarController">
        
            <div class="navbar navbar-app navbar-absolute-top">
                <div class="navbar-brand navbar-brand-center" ui-yield-to="title">
                    Mobile Angular UI
                </div>
                <div class="btn-group pull-left">
                    <div ui-toggle="uiSidebarLeft" class="btn sidebar-toggle">
                        <i class="fa fa-bars"></i> Menu
                    </div>
                </div>
                <div class="btn-group pull-right" ui-yield-to="navbarAction">
                    <div ui-toggle="uiSidebarRight" class="btn">
                        <i class="fa fa-comment"></i> Chat
                    </div>
                </div>
            </div>
        </div>

        <!-- App Body -->

        <div class="app-body">
            <ng-view class="app-content"></ng-view>
        </div>
    </div>
</body>

This image shows the layout when the navbar is visible enter image description here

This image shows the layout when the navbar is hidden

enter image description here

As you can see in the second image there is a grey section at the top. Am I dooing something wrong?

Thank you

4
  • post a fiddle so people can see your css too! It might be possible to put a class on the div with ng-controller that gives it a height of 50px instead of body having 50px padding. then wehn that is hidden, so is it's height. Commented Dec 21, 2015 at 18:02
  • 1
    Try changing the ng-hide to an ng-if. ng-if should remove the element altogether if true. Commented Dec 21, 2015 at 18:09
  • You are using ui-router? Just put the navbar inside ui-view. Commented Dec 21, 2015 at 20:56
  • I posted your "fixed" comment into an answer. You can mark it as accepted to show the problem is solved. Note in Stack Overflow changing the title to "solved" is not what we do; instead, we either post an answer of select the one that solved our issue. Commented May 13, 2016 at 10:04

2 Answers 2

1

In addition to this comment above

Try changing the ng-hide to an ng-if. ng-if should remove the element altogether if true.

Use ngClass to set a conditional class for your layout

Sign up to request clarification or add additional context in comments.

Comments

0

I solved my issue with the following html code

    <div class="app">
        <!-- Navbars -->
        <div ng-if="!isActive('/')" ng-include="'navBar.html'" ></div>

        <!-- App Body -->
        <div class="app-body">
            <ng-view class="app-content"></ng-view>
        </div>
    </div>
</body>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.