Another quick post. Working with AngularJS this morning I had a need for a link to redirect to a login page that was not contained within the “angular” part of the app. Unfortunately Angular was overriding the behavior and trying to route it.
The solution is fairly easy for this, simply add a target attribute:
Another quick one – how to stop a link from doing anything. I’ve just come across a need to use a link that acts as a button. A slight UI issue with this is that clicking a hyperlink will with an href value of ‘#’ will push scroll to the top of the page.
There are a couple of ways to go about fixing this. Note the href value in the following:
The second option is probably already familiar to anyone using ajax forms, simply have your function return false:
//Do some awesome stuff
//Return false to prevent link from affecting anything
The third option is simply a jQuery-ish rehash of number 2:
/* Does some awesome stuff while preventing the calling link from directing the user */
//Do some awesome stuff and then prevent the link from directing user
This blog gives a brief overview of when to use flash.now[notice] and when to use flash[:notice]. A basic rule of thumb is that if you’re using a redirect, use flash[:notice], if you’re simply rendering a view, use flash.now[:notice].