EVOLUTION-MANAGER
Edit File: ngHref.html
<a href='https://github.com/angular/angular.js/edit/v1.3.x/src/ng/directive/attrs.js?message=docs(ngHref)%3A%20describe%20your%20change...#L3' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit"> </i>Improve this Doc</a> <a href='https://github.com/angular/angular.js/tree/v1.3.9/src/ng/directive/attrs.js#L3' class='view-source pull-right btn btn-primary'> <i class="glyphicon glyphicon-zoom-in"> </i>View Source </a> <header class="api-profile-header"> <h1 class="api-profile-header-heading">ngHref</h1> <ol class="api-profile-header-structure naked-list step-list"> <li> - directive in module <a href="api/ng">ng</a> </li> </ol> </header> <div class="api-profile-description"> <p>Using Angular markup like <code>{{hash}}</code> 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 <code>{{hash}}</code> markup with its value. Until Angular replaces the markup the link will be broken and will most likely return a 404 error. The <code>ngHref</code> directive solves this problem.</p> <p>The wrong way to write it:</p> <pre><code class="lang-html"><a href="http://www.gravatar.com/avatar/{{hash}}">link1</a> </code></pre> <p>The correct way to write it:</p> <pre><code class="lang-html"><a ng-href="http://www.gravatar.com/avatar/{{hash}}">link1</a> </code></pre> </div> <div> <h2>Directive Info</h2> <ul> <li>This directive executes at priority level 99.</li> </ul> <h2 id="usage">Usage</h2> <div class="usage"> <ul> <li>as attribute: <pre><code><A ng-href=""> ... </A></code></pre> </li> </div> <section class="api-section"> <h3>Arguments</h3> <table class="variables-matrix input-arguments"> <thead> <tr> <th>Param</th> <th>Type</th> <th>Details</th> </tr> </thead> <tbody> <tr> <td> ngHref </td> <td> <a href="" class="label type-hint type-hint-template">template</a> </td> <td> <p>any string which can contain <code>{{}}</code> markup.</p> </td> </tr> </tbody> </table> </section> <h2 id="example">Example</h2><p>This example shows various combinations of <code>href</code>, <code>ng-href</code> and <code>ng-click</code> attributes in links and their different behaviors: <div> <a ng-click="openPlunkr('examples/example-example52')" class="btn pull-right"> <i class="glyphicon glyphicon-edit"> </i> Edit in Plunker</a> <div class="runnable-example" path="examples/example-example52"> <div class="runnable-example-file" name="index.html" language="html" type="html"> <pre><code><input ng-model="value" /><br /> <a id="link-1" href ng-click="value = 1">link 1</a> (link, don't reload)<br /> <a id="link-2" href="" ng-click="value = 2">link 2</a> (link, don't reload)<br /> <a id="link-3" ng-href="/{{'123'}}">link 3</a> (link, reload!)<br /> <a id="link-4" href="" name="xx" ng-click="value = 4">anchor</a> (link, don't reload)<br /> <a id="link-5" name="xxx" ng-click="value = 5">anchor</a> (no link)<br /> <a id="link-6" ng-href="{{value}}">link</a> (link, change location)</code></pre> </div> <div class="runnable-example-file" name="protractor.js" type="protractor" language="js"> <pre><code>it('should execute ng-click but not reload when href without value', function() { element(by.id('link-1')).click(); expect(element(by.model('value')).getAttribute('value')).toEqual('1'); expect(element(by.id('link-1')).getAttribute('href')).toBe(''); }); it('should execute ng-click but not reload when href empty string', function() { element(by.id('link-2')).click(); expect(element(by.model('value')).getAttribute('value')).toEqual('2'); expect(element(by.id('link-2')).getAttribute('href')).toBe(''); }); it('should execute ng-click and change url when ng-href specified', function() { expect(element(by.id('link-3')).getAttribute('href')).toMatch(/\/123$/); element(by.id('link-3')).click(); // At this point, we navigate away from an Angular page, so we need // to use browser.driver to get the base webdriver. browser.wait(function() { return browser.driver.getCurrentUrl().then(function(url) { return url.match(/\/123$/); }); }, 5000, 'page should navigate to /123'); }); xit('should execute ng-click but not reload when href empty string and name specified', function() { element(by.id('link-4')).click(); expect(element(by.model('value')).getAttribute('value')).toEqual('4'); expect(element(by.id('link-4')).getAttribute('href')).toBe(''); }); it('should execute ng-click but not reload when no href but name specified', function() { element(by.id('link-5')).click(); expect(element(by.model('value')).getAttribute('value')).toEqual('5'); expect(element(by.id('link-5')).getAttribute('href')).toBe(null); }); it('should only change url when only ng-href', function() { element(by.model('value')).clear(); element(by.model('value')).sendKeys('6'); expect(element(by.id('link-6')).getAttribute('href')).toMatch(/\/6$/); element(by.id('link-6')).click(); // At this point, we navigate away from an Angular page, so we need // to use browser.driver to get the base webdriver. browser.wait(function() { return browser.driver.getCurrentUrl().then(function(url) { return url.match(/\/6$/); }); }, 5000, 'page should navigate to /6'); });</code></pre> </div> <iframe class="runnable-example-frame" src="examples/example-example52/index.html" name="example-example52"></iframe> </div> </div> </p> </div>