In the end, I wrote my own directives. I needed to be sure that every change in the underlying data would be seen by the setter, but at the same time I did not want to write my own monitoring in the data model and replace everything that you usually do in the retina, with a directive that hides all this . (This will be due to the implementation of most of ng-repeat inside the directive itself.)
This is what I have (and suppose "foo" is the name of my module):
foo.directive "gridster", () -> { restrict: "E" template: '<div class="gridster"><div ng-transclude/></div>' transclude: true replace: true controller: () -> gr = null return { init: (elem) -> ul = elem.find("ul") gr = ul.gridster().data('gridster') return addItem: (elm) -> gr.add_widget elm return removeItem: (elm) -> gr.remove_widget elm return } link: (scope, elem, attrs, controller) -> controller.init elem } foo.directive "gridsterItem", () -> { restrict: "A" require: "^gridster" link: (scope, elm, attrs, controller) -> controller.addItem elm elm.bind "$destroy", () -> controller.removeItem elm return }
With this, I can create a grid-generated view by adding the following:
<gridster> <ul> <li ... ng-repeat="item in ..." gridster-item> </li> </ul> </gridster>
Whenever items are added or removed from the collection observed in the ng-repeat directive, they will automatically be added and removed from the view controlled by the grid.
EDIT
Here is a plunk demonstrating a slightly modified version of this directive:
angular.module('ngGridster', []); angular.module('ngGridster').directive('gridster', [ function () { return { restrict: 'E', template: '<div class="gridster"><div ng-transclude/></div>', transclude: true, replace: true, controller: function () { gr = null; return { init: function (elem, options) { ul = $(elem); gr = ul.gridster(angular.extend({ widget_selector: 'gridster-item' }, options)).data('gridster'); }, addItem: function (elm) { gr.add_widget(elm); }, removeItem: function (elm) { gr.remove_widget(elm); } }; }, link: function (scope, elem, attrs, controller) { var options = scope.$eval(attrs.options); controller.init(elem, options); } }; } ]); angular.module('ngGridster').directive('gridsterItem', [ function () { return { restrict: 'EA', require: '^gridster', link: function (scope, elm, attrs, controller) { controller.addItem(elm); elm.bind('$destroy', function () { controller.removeItem(elm); }); } }; } ]);