Skip to content

Commit

Permalink
Use watchCollection on the items
Browse files Browse the repository at this point in the history
  • Loading branch information
widmoser committed Apr 28, 2016
1 parent 11e8b50 commit 2fb5365
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
</fieldset>
<button type="button" class="btn btn-default" ng-click="fixSize()">Fix size</button>
<button type="button" class="btn btn-default" ng-click="changeData()">Change Data</button>
<button type="button" class="btn btn-default" ng-click="insert()">Insert</button>
</form>
</div>

Expand Down Expand Up @@ -96,13 +97,26 @@
};

$scope.parentScopeValue = 'Outer scope';

$scope.insert = function() {
$scope.data.splice(0, 0, {
id: $scope.data.length,
name: "Some Test Name " + $scope.data.length
});
};

$scope.remove = function(item) {
$scope.data.splice($scope.data.indexOf(item), 1);
};
}]);
</script>
<script type="text/ng-template" id="SimpleCell">
<div class="item-cell-padding">
<div class="item-cell">
<p>{{ item.name }}</p>
<p>{{ parentScopeValue }}</p>
<div>
<button class="btn btn-default" ng-click="remove(item)">Remove</button>
</div>
</div>
</div>
</script>
Expand Down
2 changes: 1 addition & 1 deletion dist/tileview.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
});
layout();
});
scope.$watch('items', function () {
scope.$watchCollection('items', function () {
lastScrollPosition = Number.NEGATIVE_INFINITY;
layout();
});
Expand Down
2 changes: 1 addition & 1 deletion src/tileview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ declare const angular: any;
});
layout();
});
scope.$watch('items', () => {
scope.$watchCollection('items', () => {
lastScrollPosition = Number.NEGATIVE_INFINITY;
layout();
});
Expand Down

0 comments on commit 2fb5365

Please sign in to comment.