-
Notifications
You must be signed in to change notification settings - Fork 109
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
Toggle Menu not working in Angular #398
Comments
Are there any errors in the browser console? |
Haven’t used Angular in a while so I will ask around to see if anyone else has tried using it with Angular and I will see if I can replicate it. |
Ok. Thanks Adam! |
If you are keen to get it working (whilst we investigate further) you could use the compiled You can find instructions here: https://github.com/nhsuk/nhsuk-frontend/blob/master/docs/installation/installing-with-npm.md#option-1-include-compiled-javascript |
My guess would be that the header JS is trying to select the menu button before it's been rendered to the page. Here, we are doing the select outside of the initialisation function, when it should be inside. |
Just tried a bit of debugging, stepping into Header.js. Also, I've pushed this project up: https://github.com/puravupadhyay/nhsuk-frontend-angular Cheers |
Globally scoped variables were causing issues with JavaScript frameworks such as Angular, so they have been moved to be locally scoped within functions. This could be improved as we have to duplicate variables.
The wrap-search element was not being found as the page load event listener was coming after the search for the element which caused issues in JavaScript frameworks such as Angular.
Just to let you know, I've opened a draft pull request with a potential fix for this #402 I'm just testing it out with your Angular application (and other applications) now. Also looking at potential ways we could improve our JavaScript, so if you have any advice that would be greatly appreciated. Thanks for raising this with us, hopefully we should get it fixed soon. |
The wrap-search element was not being found as the page load event listener was coming after the search for the element which caused issues in JavaScript frameworks such as Angular.
Thanks @AdamChrimes for that. I tested the changed files and they're working. Just a thought - could use the namespaces in JavaScript - not 100% confident that it will work. Will have to play-around with it a bit, I'll try and set the project up my end. I guess this is the best place to look for guidance on that: https://github.com/nhsuk/nhsuk-frontend/tree/master/docs/contributing Cheers |
Globally scoped variables were causing issues with JavaScript frameworks such as Angular, so they have been moved to be locally scoped within functions. This could be improved as we have to duplicate variables.
The wrap-search element was not being found as the page load event listener was coming after the search for the element which caused issues in JavaScript frameworks such as Angular.
Hi @puravupadhyay, we've just released version 2.0.0 of the Frontend library. With this release is the fix we mentioned above for the JavaScript variables. I've just tested it with your Angular repo with We're still looking at improving our JavaScript overall in the issue #408 but this should fix it in the meantime. Thanks again for raising this issue, it will be good to keep in touch. Do you use Slack? We have a public Slack instance which may easier to share progress https://nhs-service-manual.slack.com/ |
@AdamChrimes The new version works! Would be great to use it in future projects. Sure, how do I join https://nhs-service-manual.slack.com/ ? I don't think I have a Slack account. |
Great thanks @puravupadhyay You will need to create an account (its free) you can sign up with your @nhs.net email address here: https://nhs-service-manual.slack.com/signup or if you want to use another email account provider you can use this link You can use Slack in the browser or you can download the application. Not to worry if you're not wanting to join Slack - just a useful tool for instant message and sharing quickly. |
Closing as this is fixed in version 2.0.0. |
Bug Report
What is the issue?
I'm trying to use this library in an Angular project. I installed nhsuk-frontend via npm fine.
I managed to import the styles and can see all the component rendering but I'm having problems with the javascript files. I imported all the modules like suggested but not able to make the Menu Toggle work. Can someone please help?
What steps are required to reproduce the issue?
What was the environment where this issue occurred?
Is there anything else you think would be useful in recreating the issue?
This is the sample code of app.component.ts file:
The text was updated successfully, but these errors were encountered: