javascript - how to update a list inside ng-repeat using angular? -
i lave ionic list
<ion-list> <ion-item ng-repeat="item in items"> hello, {{item.name}}! </ion-item> </ion-list>
then, in controller have event:
$scope.items = somedata(); itemsref.on('event', function (response) { console.log(response); // object containing "name" property });
i append response
ion-item
, without inserting html, somehow adding response items
edit:
i've tried: $scope.items.push(response);
weirdly enough uncaught typeerror: undefined not function
edit: looks 1 doesn't $scope.items.push(response);
, $scope.items[next_key_here] = response;
see jsfiddle
i've tried:
$scope.items.push(response);
weirdly enoughuncaught typeerror: undefined not function
that happens because $scope.items isn't array
object when access before hasn't been populated value yet. try doing this, should work:
if ($scope.items && $scope.items instanceof array) { $scope.items.push(response); }
Comments
Post a Comment