Note that there are some explanatory texts on larger screens.

plurals
  1. POUI is not updated after firering a ng-click event on my AngularJS controller
    primarykey
    data
    text
    <p>I've bound a button with a ng-click event that fires a function on my controller. This again gets some data using $http and this works just fine. But when updateing my model in the success-callback the UI doesnt get updated. I've tried using $scope.$apply and $scope.safeApply without luck. Nothing happens in the UI. Data is returned from service. See code below.</p> <p>SearchController:</p> <pre><code>'use strict'; searchApp.controller('SearchController', function SearchController($scope, searchData) { $scope.query = ''; $scope.isLoading = false; $scope.result = null; $scope.doSearch = function () { $scope.isLoading = true; searchData.getSearchResult($scope.query, function (result) { $scope.safeApply(function() { $scope.result = result; console.log($scope.result); }); }); }; $scope.safeApply = function (fn) { var phase = this.$root.$$phase; if (phase == '$apply' || phase == '$digest') { if (fn &amp;&amp; (typeof (fn) === 'function')) { fn(); } } else { this.$apply(fn); } }; } ); </code></pre> <p>HTML markup:</p> <pre><code>&lt;div class="search-result" ng-controller="SearchController"&gt; &lt;input type="text" value="Enter query..." ng-model="query" /&gt; &lt;input type="button" value="Search" ng-click="doSearch()" /&gt; &lt;div ng-show="isLoading"&gt; Searching.... &lt;/div&gt; &lt;h2&gt;{{ result.SearchGroups }}&lt;/h2&gt; &lt;div class="result-box" ng-repeat="group in result.SearchGroups"&gt; &lt;div class="head"&gt; &lt;h2&gt;{{ group.Name }}&lt;/h2&gt; &lt;!--&lt;span class="seeAll"&gt;Se alle (13)&lt;/span&gt;--&gt; &lt;/div&gt; &lt;div class="body"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    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