Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating Angular originally loaded via JSONP
    text
    copied!<p>I have a resource that returns a JSONP payload:</p> <pre class="lang-js prettyprint-override"><code>app.factory('JsonService', function($resource) { return $resource('//123.456.7.890\\:8888/user/:id/:model', {'page': ':page', 'limit' : ':limit', 'jsonp_callback' : 'JSON_CALLBACK'}, {}) }); </code></pre> <p>Which gets called by my controller:</p> <pre class="lang-js prettyprint-override"><code>app.controller("followersCtrl", function ($scope, $dialog, JsonService) { ... $scope.user_id = $.globals.authed_user_id; $scope.model = "followers" $scope.loadJSONP = function (getPage) { JsonService.get({ id: $scope.user_id, page: getPage, limit: $scope.pagination_limit, model: $scope.model }, function (data) { $scope.followers = data; $scope.noOfPages = data.page_count; $scope.currentPage = data.page; }); }; $scope.loadJSONP(1); $scope.pageChanged = function (page) { $scope.callbackPage = page; $scope.loadJSONP(page); }; }); </code></pre> <p>Then I loop over the data returned/stored in <code>$scope.followers</code>:</p> <pre class="lang-html prettyprint-override"><code>&lt;div ng-controller="followersCtrl"&gt; ... // Code related to the modal omitted ... &lt;div ng-repeat="user in followers.data"&gt; &lt;img class="img img-polaroid" ng-src="{{user.image_url}}"/&gt; &lt;p&gt;{{ user.username }}&lt;/p&gt; &lt;button class="btn btn-disabled" ng-show="user.is_mutual"&gt; You Are following this user &lt;/button&gt; &lt;button class="btn btn-primary" ng-show="!user.is_mutual"&gt; You Aren\'t following &lt;/button&gt; &lt;p&gt;{{user.total_followers}}&lt;/p&gt; &lt;/div&gt; ... // Code related to the modal omitted ... &lt;/div&gt; </code></pre> <p>That all works as expected, but for the life of me I <strong>cannot</strong> figure out how to have the "You are not following" button change the value that's reflected inside the corresponding <code>{{post.total_followers}}</code> expression on click. Ideally, I would like to perform a <code>PUT</code> to actually perform the follow action, but I decided to start small and just update the value, to no avail. </p> <p>Any help is appreciated. Thank you. </p>
 

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