Skip to content

Commit 2fb5365

Browse files
committed
Use watchCollection on the items
1 parent 11e8b50 commit 2fb5365

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

demo/index.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
</fieldset>
4848
<button type="button" class="btn btn-default" ng-click="fixSize()">Fix size</button>
4949
<button type="button" class="btn btn-default" ng-click="changeData()">Change Data</button>
50+
<button type="button" class="btn btn-default" ng-click="insert()">Insert</button>
5051
</form>
5152
</div>
5253

@@ -96,13 +97,26 @@
9697
};
9798

9899
$scope.parentScopeValue = 'Outer scope';
100+
101+
$scope.insert = function() {
102+
$scope.data.splice(0, 0, {
103+
id: $scope.data.length,
104+
name: "Some Test Name " + $scope.data.length
105+
});
106+
};
107+
108+
$scope.remove = function(item) {
109+
$scope.data.splice($scope.data.indexOf(item), 1);
110+
};
99111
}]);
100112
</script>
101113
<script type="text/ng-template" id="SimpleCell">
102114
<div class="item-cell-padding">
103115
<div class="item-cell">
104116
<p>{{ item.name }}</p>
105-
<p>{{ parentScopeValue }}</p>
117+
<div>
118+
<button class="btn btn-default" ng-click="remove(item)">Remove</button>
119+
</div>
106120
</div>
107121
</div>
108122
</script>

dist/tileview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
});
101101
layout();
102102
});
103-
scope.$watch('items', function () {
103+
scope.$watchCollection('items', function () {
104104
lastScrollPosition = Number.NEGATIVE_INFINITY;
105105
layout();
106106
});

src/tileview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ declare const angular: any;
109109
});
110110
layout();
111111
});
112-
scope.$watch('items', () => {
112+
scope.$watchCollection('items', () => {
113113
lastScrollPosition = Number.NEGATIVE_INFINITY;
114114
layout();
115115
});

0 commit comments

Comments
 (0)