5

If there's an ng-click and a href together on an anchor the ng-click doesn't work. I want both to work if possible, go to a route and then run a function. My use-case is I have a drawer open with a panel of links, when going to a link I want to close the drawer.

What's an easy way to get both working at the same time?

1
  • you can either redirect using href of use ng-click Commented Jul 18, 2013 at 7:21

2 Answers 2

6

Once you navigate away from the page scripts no longer run.*

Your flow can be something like:

When the user clicks, run a function that does the following:

  • Run the original function you wanted to run
  • Handle any 'navigate away in this specific case' logic.
  • Change location.href to the URL you want to to navigate to.

It's of course possible to extract this behavior to a directive if you find yourself implementing that bit of logic over and over :)

* You can use onbeforeunload but that's not good for plenty of other reasons

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

Comments

0

The question was asking for the wrong thing. Using the href and the ng-click together works perfectly fine, I just had an ui-view in the parent element that prevented any angular bindings from working at all.

2 Comments

Is ui-view an Angular directive?
@Weiming - Yes, ui-view belongs to uiRouter: github.com/angular-ui/ui-router

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.