What is the best method for passing data back to the parent scope in AngularJS without using isolated scopes?
Imagine I have a directive called x
, and I want to access its value named a
. The desired syntax would be:
<x a="some.obj.myA"></x>
current a: {{some.obj.myA}}
To implement the x
directive, I would do the following:
app.directive('x', function() {
var a = {};
return {
restrict: 'E',
link: function($scope, $element, $attrs) {
var parentExpression = $attrs.a;
// ???
},
replace: true,
template: ...
};
});
Essentially, my goal is to always ensure that "$scope.$parent[parentExpression]
" (pseudo code) remains equal to the local variable a
's value. This should work seamlessly even if parentExpression
points to a complex nested object, array, or any other assignable expression.
How can I achieve this functionality?