Ok I have a similar problem to these two posts:
AngularJS: Parent scope not updated in directive (with isolated scope) two way binding
AngularJS: Parent scope is not updated in directive (with isolated scope) two way binding
I have a directive with an isolated scope, which is called like this:
<sy-form form-values="customerData" on-save="save(customerData)"></sy-form>
The save(customerData) method is on the parent scope and is invoked via a button click, which triggers the following method on the isolated scope:
$scope.save = function () {
$scope.formValues = angular.copy($scope.formValuesEditable);
var updatePromise = $scope.onSave();
...
};
The save(customerData) method on the parent scope looks like this:
scope.save = function (customerData) {
return customerApi.update(customerData);
};
The problem of course is that I am changing the formValues object with this line of code:
$scope.formValues = angular.copy($scope.formValuesEditable);
there is not digest cycle between this and the call to $scope.onSave() -> save(customerData), so the two way data binding does not sync the customerData property on the parent scope and the not edited object is being saved.
Reading through the various posts it seems that the only solution to this is to call $scope.onSave(); in a $timeout. But this feels a bit hacky. Do you think it is a good idea to use $timeout to work around this or there is a better way?