I am experiencing an issue with a directive that has an isolated-scope and one-way binding variable. Despite setting up the directive to keep the scope separate, any changes made to the variable in the directive controller also update the parent scope.
Below is an example of the code:
function someDirective() {
return {
restrict: 'E',
replace: true,
scope: {},
bindToController: {
parentVar: '<'
},
templateUrl: templateUrl,
controller: directiveController,
controllerAs: 'vm'
}
}
function directiveController($scope) {
var vm = this;
$scope.$watchCollection('vm.parentVar', doSomething);
function doSomething(newCollection) {
var some_object = {
property1: 1,
property2: 2
};
newCollection.unshift(some_object);
}
}
Despite my efforts to only update the passed variable within the directive, the presence of some_object
can be seen in other areas of my application after making changes.
Your help is greatly appreciated.