javascript - Reload ng-repeat angular / ionic -


i read discussions problem no 1 works me.

i have 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 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 cases console.log($scope.friends); return expected value

and 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 updated in console output list not change.

i tried add $scope.$apply have $digest in progress

you try this, while don't know apiuser does:

.controller('testfriendctrl', ['$scope', 'apiuser', function($scope, apiuser) {     $scope.friends = [{username: 'test'}];      $scope.change = function(friend) {         apiuser.find(friend).$promise.then(function(success, data){             if (success) {                 $scope.friends = data;                 console.log($scope.friends);             }         }, function (err) {             console.log(err);         )};     } }]); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -