После некоторого исследования, и со ссылкой на following issue, вот расширение Scope, что позволяет связыванию двухстороннего (это, по существу, Угловой код, только модифицирована для работы за пределами nodeLinkFn
):
angular.module('scopeBindExtention', [])
.run([ '$rootScope', '$parse', function($rootScope, $parse) {
var extended = angular.extend($rootScope, {});
extended.$bindTwoWay = function(scopeName, parentName) {
var scope = this,
parentScope = scope.$parent;
lastValue,
parentGet,
parentSet,
compare;
parentGet = $parse(parentName);
if (parentGet.literal) {
compare = angular.equals;
} else {
compare = function(a,b) { return a === b; };
}
parentSet = parentGet.assign || function() {
// reset the change, or we will throw this exception on every $digest
lastValue = scope[scopeName] = parentGet(parentScope);
throw new Error("Expression '" + parentName + "' is non-assignable!");
/*
throw $compileMinErr('nonassign',
"Expression '{0}' is non-assignable!",
parentName);
*/
};
lastValue = scope[scopeName] = parentGet(parentScope);
var unwatch = parentScope.$watch($parse(parentName, function parentValueWatch(parentValue) {
if (!compare(parentValue, scope[scopeName])) {
// we are out of sync and need to copy
if (!compare(parentValue, lastValue)) {
// parent changed and it has precedence
scope[scopeName] = parentValue;
} else {
// if the parent can be assigned then do so
parentSet(parentScope, parentValue = scope[scopeName]);
}
}
return lastValue = parentValue;
}), null, parentGet.literal);
scope.$on('$destroy', unwatch);
}
}]);
Клиентам следует только позвонить:
scope. $ BindTwoWay ('childModelName', 'parentModelName');
Почему просто поместите 'obj.name = 'thename'' и используйте' my-attr = "obj" '? –