I have created a directive and I believe that two-way bind is being broken when I set a bound scope variable (textStyleOriginal) to null. What is a good way to resolve this issue?
.directive('textStylePalette', function($log, toastr, _){
return {
restrict: 'E',
templateUrl: 'app/palettes/text/text-style-palette.html',
scope: {
textStyleOriginal: '=textStyle'
},
link: textPaletteLinkFn
};
function textPaletteLinkFn(scope, elem, attr) {
scope._ = _;
scope.textStyle = null;
// Used when closing the palette
scope.deselectStyle = function() {
// I BELIEVE THE PROBLEM IS THE NEXT LINE
scope.textStyleOriginal = null;
scope.textStyle = null;
};
...
// THIS WATCH STOPS WORKING.
scope.$watch('textStyleOriginal', function(newVal, oldVal){
$log.debug('n: ' + newVal + '|o: ' + oldVal );
debugger;
if (newVal && newVal !== oldVal) {
...
}
});
}
The html where the binding is initially connected is as follows:
<text-style-palette ng-show="selectedStyle !== null" text-style="selectedStyle">
</text-style-palette>