I already read some discussions about this problem but no one works for me.
I have a controller
.controller('TestFriendCtrl', ['$scope', 'APIUser', function($scope, APIUser) {
$scope.data.friends = [{username: 'test'}];
$scope.change = function(friend) {
APIUser.find(friend, function(success, data){
if (success) {
$scope.data.friends = data;
console.log($scope.data.friends);
}
})
}
}]);
I also tried
.controller('TestFriendCtrl', ['$scope', '$timeout', 'APIUser', function($scope, $timeout, APIUser) {
$scope.friends = [{username: 'coucou'}];
$scope.change = function(friend) {
APIUser.find(friend, function(success, data){
if (success) {
$timeout(function() {
$scope.friends = data;
console.log($scope.friends);
} );
}
})
console.log($scope.friends);
}
}]);
and
.controller('TestFriendCtrl', ['$scope', '$timeout', 'APIUser', function($scope, $timeout, APIUser) {
$scope.friends = [{username: 'coucou'}];
$scope.change = function(friend) {
APIUser.find(friend, function(success, data){
if (success) {
$scope.friends = angular.copy(data);
}
})
console.log($scope.friends);
}
}]);
In all cases console.log($scope.friends);
return the expected value
And a view
<ion-view class="main-page">
<ion-content>
<h1>Friend</h1>
<label class="item item-input">
<i class="icon ion-search placeholder-icon"></i>
<input ng-model="friend" name="friend" type="search" placeholder="Search" ng-change="change(friend)">
</label>
{{ data.friends[0].username }}
<ion-list ng-controller="TestFriendCtrl" >
<ion-item ng-repeat="friend in data.friends" class="item-thumbnail-left">
<p>{{friend.username}}</p>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
the $scope.friend
is well updated in the console output but my list does not change.
I tried to add $scope.$apply
but I have $digest already in progress