Isolated areas are usually only useful with templates; they should not be used as a way to declare how you want your directive attributes to be interpreted. This is due to the fact that most directives that do not have a template usually need the semantics of either a childβs area or a direct area of ββtheir environment.
In your case, you probably don't even need $ watch, because object references are something that allow you to bind 2-way data, but without your complete code, I cannot be sure.
If you want translations for the selected area semantics to be just normal:
@name -> attrs.name =name -> $scope.$eval(attrs.name); &name -> function() { return $scope.$eval(attrs.name); }
EDIT 2:
After your comment, I came up with this plunker . To preserve two-way data binding, you must use ".". in the ng model declaration. This is because two-way data binding does not work for value types, because they are immutable. You cannot change the value 100, for example. You need to pass an object of a reference type and hang up the values ββthat you are changing. Your desire to indicate the full path to the value in the definition of an isolated area is not possible based on the principles that provide the possibility of two-way data binding.
JavaScript:
angular.module('plunker', []) .directive('twoWay', function() { return { restrict: 'E', template: '<div><input ng-model="thing.name" type="text" /></div>', scope: { thing: "=" }, link: function(scope, element, attrs) { } }; }) .controller('MainCtrl', function($scope) { $scope.data = { name: "World" }; });
HTML:
<body ng-controller="MainCtrl"> <p>Hello {{data.name}}!</p> <two-way thing="data"></two-way> </body>
source share