Thursday, 15 August 2013

javascript - Data not showing until I start to filter? -



javascript - Data not showing until I start to filter? -

i trying utilize info binding feature of angularjs show list of info send ajax request for. new angularjs know i'm missing here. info beingness populated shows if include text box ng-model directive , begin typing in it.

i know code isn't best practice i'm trying in sharepoint , i'm having problem using modules , factories i'm trying simple demo setup first. help much appreciated.

code

class="lang-html prettyprint-override"><!-- info not show until start typing in text box other not need it. --> <input ng-model="foo" /> <ul ng-controller="simplecontroller"> <li ng-repeat="item in discussions"> {{item.title}} </li> </ul> class="lang-js prettyprint-override">function simplecontroller($scope) { $.ajax({ url: requesturi, type: "get", headers: { "accept": "application/json;odata=verbose", }, success: function (data) { $scope.discussions = data.d.results; console.log("simplecontroller success callback"); }, error: function (err) { alert(err); } }); }

i believe what's happening angular not know when $.ajax phone call complete, technically utilize if ( $scope.$$phase ) $scope.$apply(), i'd recommend rebuilding $.ajax "the angular way":

function simplecontroller($scope, $http) { $http.get( requesturi ) .then(function( json ) { console.log( json ); $scope.discussions = json.data; }); }

more reading:

$scope.$apply: manually tell angular recalculate scope upon changing info outside of angular data, e.g. jquery. $http: angular version of $.ajax , automatically handles $scope.$apply (recommended)

javascript angularjs data-binding

No comments:

Post a Comment