Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS http request is never executed
    primarykey
    data
    text
    <p>I have a minimal plunk of this <a href="http://plnkr.co/edit/zVblhH?p=preview" rel="nofollow">here</a>.</p> <p>Here's what's happening:</p> <ol> <li>initial <code>$http</code> request is made successfully</li> <li>a click event is bound to a button in a directive</li> <li>clicking the button fires the desired function</li> <li>the <code>$http</code> request in that function (identical to the request in step 1) does not fire</li> </ol> <p>Because the code is short, I'll post it here, too.</p> <h3>template</h3> <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html ng-app="plunker"&gt; &lt;head&gt; &lt;title&gt;AngularJS Plunker&lt;/title&gt; &lt;!-- angular source --&gt; &lt;script src="app.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body ng-controller="MainCtrl"&gt; &lt;p&gt;Click this button and an http request should log to the console&lt;/p&gt; &lt;button make-request act='flip()'&gt;Get Gaius&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <h3>controller</h3> <pre class="lang-coffee-script prettyprint-override"><code>app = angular.module('plunker', []) app.controller 'MainCtrl', ($scope, $http) -&gt; # this function is just here to show that no errors are thrown err = (err) -&gt; console.log 'err', err # this successfully gets $http.get('gaius.json') .then ((res) -&gt; console.log 'init data', res.data), err $scope.flip = -&gt; # although this function is called, console.log 'called to act' # http does not get. No request is made. $http.get('gaius.json') .then ((res) -&gt; console.log 'flip data', res.data), err app.directive 'makeRequest', ($compile) -&gt; scope: act: '&amp;' link: (scope, element, attrs) -&gt; element.bind 'click', (e) -&gt; scope.act() </code></pre> <h3>data</h3> <pre class="lang-json prettyprint-override"><code>{ "name": "gaius baltar" } </code></pre> <p>Any idea why that request doesn't execute?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload