some tricky in ng-repeat update model in ionic

ng-repeat is to loop thought object list and auto generated html.

for example
in controller, we declare
$scope.workspaces.

Now $scope.workspaces = getDataFromDatabase();

1
2
3
<li class="workspace-object" ng-repeat="w in workspaces | filter:searchQuery" ng-click="selectWorkspace(w)">
    <a href="" class="workspace-link">{{w.name | titleCase }}</a>
</li>

It will not updated.

Make following change it will work.

1
2
$scope.work={}; //very important, declare object first.
$scope.work.workspaces = getDataFromDatabase(); //workspaces object should under work object.

change ng-repeat to be ng-repeat=”w in work.workspaces | filter:searchQuery”

This entry was posted in Angular.js. Bookmark the permalink.