Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navbar not collapsing without ui-bootstrap #458

Closed
Kageetai opened this issue Aug 17, 2014 · 10 comments
Closed

Navbar not collapsing without ui-bootstrap #458

Kageetai opened this issue Aug 17, 2014 · 10 comments
Labels

Comments

@Kageetai
Copy link

Hey,

I just tried out the generator and noticed after some changes to the generated project, that the navbar is not collapsing. It seems the directive "collapse" is missing or at least I cannot find it. Am I missing something here?

@Kageetai
Copy link
Author

Ah btw, even after going back to my very first commit without any changes to the generated code, the navbar is not working.

@kingcody
Copy link
Member

Did you include ui-bootstrap? If not, there is a good chance that the bootstrap vendor script has already fired off before the navbar was loaded. If you're not using bootstrap-ui, you'll need to manually initialize the collapse behavior. Check out the docs for more info on collapse and how to initialize it.

Let me know if that does the trick.

@Kageetai
Copy link
Author

Okay, I tried it out with two clean installs, one with ui-bootstrap and one without. With ui-bootstrap included in the build, it works fine. I'll try to manually run the collapse script, but I would be good to fix the generator too or at least notify new users somewhere, wouldn't it?

@Kageetai Kageetai changed the title Navbar not collapsing Navbar not collapsing without ui-bootstrap Aug 18, 2014
@kingcody
Copy link
Member

I'm not sure what the right course of action is, but I do know this is typical behavior with asynchronous page loading, ie: DOM gets added after document.ready.

@kingcody
Copy link
Member

Actually, the proper thing to do would be write a directive for the behavior.
In simplest form:

angular.module('YOUR_APP_NAME')
  .directive('navbarCollapse', function () {
    return function postLink(scope, element) {
      var nav = element.find('.navbar-collapse').collapse();
      element.find('button.navbar-toggle').click(function() { nav.collapse('toggle'); });
    };
  });

Then just place the navbar-collapse attribute on the div.navbar.navbar-default element.

@JaKXz JaKXz added the question label Aug 19, 2014
@JaKXz
Copy link
Collaborator

JaKXz commented Aug 19, 2014

Great answer @kingcody.

@JaKXz JaKXz closed this as completed Aug 19, 2014
@Kageetai
Copy link
Author

Thanks for the answer!

@tmeani
Copy link

tmeani commented Oct 24, 2014

+1

@Kageetai
Copy link
Author

Hi again,
I finally got to try out @kingcody s code and also had to include bootstrap.js in wiredep like in #565. One change to you code though: I removed the first collapse otherwise the navbar would stark opened.

@raosushant
Copy link

raosushant commented May 7, 2016

Depending on your version of UI-Bootstrap you might have to modify

collapse='nav.isCollapsed'
to
uib-collapse ='nav.isCollapsed'
in navbar.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants