JRoller JRoller - 8 months ago 29
jQuery Question

ng-repeat doesn't fire the second time after $scope changes

I'm new to Angular and trying to create a filtering mechanism that fires a search when typing a letter, looking it up the db and returning results.

The results are returning ok from the DB, but the issue i'm having is when i'm filling the scope array with the results and ng-repeat doesn't fire.

my HTML and JS:

$scope.results =[];
$scope.onTextChange = function (){
var results = [];
var text = $scope.friendsLookupText;
url: 'utilities/getFriendsByValue.php',
method: 'POST',
data: {textValue: text}
}).success(function(data) {
$scope.results = results;
var stringResult = JSON.stringify(data);
var parsedResult = JSON.parse(stringResult);
$scope.results = parsedResult;


<div class="container-fluid" ng-controller="friendsController as friendsCtrl">
<input type="text" id="friendsLookupText" ng-model="friendsLookupText" ng-change="onTextChange()">
<ul class="list-group">
<div class="" ng-repeat="result in $scope.results">
<li class="list-group-item">{{result.username}}</li>

I'll be glad if anyone could help.


Remove $scope from the repeat in the view, use only results

<div class="" ng-repeat="result in results">
     <li class="list-group-item">{{result.username}}</li>