Is the angular scope binding &(ampersand) a one time binding? I see it referred to as a one-way binding, but is it also one-time?
Let's say I have:
<my-custom-directive data-item="item" />
And my directive is declared as follows:
.directive('myCustomDirective', [
'$log', function ($log) {
return {
restrict: 'E',
templateUrl: '/template.html',
scope: {
dataItem: '&'
}
controller: function ($scope) {
// ....
}
}])
The reason I'm asking if the binding is one-time is because that seems to be what I'm observing, that is. If item
in the parent scope is updated, the one in the directive is not updated.
Am I correct in assuming that the binding is one-time?
To achieve what I want, where the directive keeps a copy without affecting the parent scope's item -- I did this:
.directive('myCustomDirective', [
'$log', function ($log) {
return {
restrict: 'E',
templateUrl: '/template.html',
scope: {
dataItemOriginal: '='
},
link: function ($scope) {
$scope.$watch('dataItemOriginal', function () {
$scope.dataItem = window.angular.copy($scope.dataItemOriginal);
});
},
controller: function ($scope) {
//....
}
}])
Is this the correct approach or is there a more efficient way to achieve this?