Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

One way binding for objects in directive #12835

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
var EVENT_HANDLER_ATTR_REGEXP = /^(on[a-z]+|formaction)$/;

function parseIsolateBindings(scope, directiveName, isController) {
var LOCAL_REGEXP = /^\s*([@&]|=(\*?))(\??)\s*(\w*)\s*$/;
var LOCAL_REGEXP = /^\s*([@&#]|=(\*?))(\??)\s*(\w*)\s*$/;

var bindings = {};

Expand Down Expand Up @@ -2663,6 +2663,31 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
return parentGet(scope, locals);
};
break;

case '#':
parentGet = attrs.hasOwnProperty(attrName) ? $parse(attrs[attrName]) : noop;

if (parentGet === noop && optional) break;

var parentValue = parentGet(scope);

if (!isObject(parentValue))
throw $compileMinErr('nonassign',
"Attribute value has to be an object in directive '{0}'." +
" Definition: {... {1}: '{2}' ...}",
directive.name, scopeName, definition);

destination[scopeName] = copy(parentValue);

var unwatch;
unwatch = scope.$watch(function parentValueWatch() {
return $parse(attrs[attrName])(scope);
}, function onParentValueChange(newParentValue) {
destination[scopeName] = copy(newParentValue);
});
onNewScopeDestroyed = (onNewScopeDestroyed || []);
onNewScopeDestroyed.push(unwatch);
break;
}
});
var destroyBindings = onNewScopeDestroyed ? function destroyBindings() {
Expand Down