I have a create function in a service which is responsible for taking input data, turning it into a resource, doing a save and inserting it into a local cache.
create = (data, success, error) ->
throw new Error("Unable to create new user, no company id exists") unless $resource_companies.id()
# create the resource
new_model = new resource(data)
# manually add the company id into the payload (TODO: company id should be inferred from the URL)
new_model.company_id = $resource_companies.id()
# do the save and callbacks
new_model.$save( () ->
list.push(new_model)
success.call(@) if success?
, error)
My problem is that an ng:repeat that watches the list variable is not getting updated. As far as I can tell this is not occurring outside on AngularJS so it does not require a $scope.$apply() to keep it up to date (indeed, if I try to trigger a digest, I get a digest already in progress error)
What's doubly weird, is I have this exact same pattern used elsewhere without issue.
The code used by my controller to access the list array is (this is in the service)
# refreshes the users in the system
refresh = (cb) -> list = resource.query( () -> cb.call(@) if cb? )
In the controller:
$scope.users = $resource_users.refresh()