Questions tagged [angularjs-ng-href]

Part of AngularJS. Using Angular markup like {{hash}} in an href attribute will make the link go to the wrong URL if the user clicks it before Angular has a chance to replace the {{hash}} markup with its value. Until Angular replaces the markup the link will be broken and will most likely return a 404 error. The ngHref directive solves this problem.

The wrong way to write it:

<a href="http://www.gravatar.com/avatar/{{hash}}">link1</a>

The correct way to write it:

<a ng-href="http://www.gravatar.com/avatar/{{hash}}">link1</a>

Usage

<A
  ng-href="template">
...
</A>

Reference - AngularJS ngHref docs

55 questions
1
vote
3 answers

AngularJS - change href Attribute based on current path

How can I change the value of the href-Attribute based on the current path? My if clause in AngularJS looks like this: if (newPath.indexOf('test') > -1) { // change the value of the href-Attribute } else { // don't change the…
1
vote
0 answers

angular ng-href read from scope not working

here is my downloadable link : download.xxxxxx.com/yyyyy.json for company policy reason, I use xxxxxx and yyyyy to illustrate domain and json file name. but I have tested on my end, this is a downloadable link. HTML
Qing Xu
  • 175
  • 1
  • 11
1
vote
1 answer

ng-href="#/myanchor" not working anymore as usual with angularjs 1.6.1

I used to work with angularjs 1.5.8. For professional reasons I need to migrate to version 1.6.1 and I need to use ng-href to go to an anchor that I configured. So when I write in my code: link In my browser,…
kabrice
  • 1,475
  • 6
  • 27
  • 51
1
vote
0 answers

ng-click and ngRouting on mobile devices

I am completely new to Angularjs and haven’t been doing any code for ages. I started setting up my website again with Angularjs. I have a main page and an about page, to which the user gets via ngRoute on ng-click (or hitting space). Once on the…
1
vote
1 answer

Using ng-href as a filter function

Is there anyway to pass a string through ng-href and achieve the same result as if it was the value of that directive? e.g. {{ url | ng-href }} So that way the filter or pipe sanitizes any values and conforms the proper url scheme.
chrisjlee
  • 21,691
  • 27
  • 82
  • 112
1
vote
2 answers

Sip not working in AngularJs

I am getting the user details from a webservice. Everything is fine except that the javascript is adding an unsafe attribute to the email Id field.
Created By
1
vote
2 answers

Angularjs error validation for dropdown/select redirect with ng-href

I'm currently using angularjs's ng-href and a select html element with ng-model where I am using ng-href to link to the "selectedItem" (from ng-model). I was unable to validate or provide an error when nothing was chosen and was wondering how I…
mding5692
  • 806
  • 1
  • 10
  • 34
1
vote
2 answers

Change CSS Style Sheet on click with Ionic Framework

I have a basic Ionic App and would like to apply one of three different style sheets based on a User Input. The page will be pre-loaded with the basic style, then a user can select two other options, so far the original style is loaded and I can…
1
vote
1 answer

open in new tab using right click not working angularjs using ng-repeat, ng-href and ng-click

this is my code..
schneider
  • 273
  • 1
  • 3
  • 8
1
vote
1 answer

using ng-href with javascript in anchor tag (bookmarklet)

I am trying to create a bookmarklet on an anchor tag using angularjs. When the script is static, there is no need to use angularjs code. but when it is dynamic, both href and ng-href are appending 'unsafe' to the JavaScript. tried DOM manipulation…
CodingNinja
  • 801
  • 9
  • 17
1
vote
1 answer

Equivalent to ui-router's "ui-sref" in ngRoute?

Is there any kind of equivalent to ui-router's ui-sref? As of now all my ng-href's are hard-coded string literals, ex; which makes me shiver whenever I see it. Are there any built-in…
William Boman
  • 2,079
  • 5
  • 26
  • 39
1
vote
1 answer

AngularJS ngHref why lowercase

I'm trying to bind href attribute to my link using ngHref, but AngularJS lowercases it. How can I avoid this behavior? {{preview.title}} It lowercases preview.hash, I'd like not to do this.
let4be
  • 1,048
  • 11
  • 30
0
votes
1 answer

How to replace the `vue:href` method

:href="" is scanned by sonarqube, showing Take care when using the v-bind:href directive to set URLs which can contain malicious Javascript (javascript:onClick(…)). Brothers and sisters, is there any way to replace :href?
Tom Kale
  • 9
  • 3
0
votes
0 answers

AngularJS Filter with encodeURIComponent Not Working in Link

I am trying to encode a value passed in an URL using a filter that calls encodeURIComponent. My original filter angular. module('machineorderDetail'). filter('encodeURIComponent', function () { return window.encodeURIComponent; …