(scope, attrs, destination, bindings, directive)
| 10713 | |
| 10714 | // Set up $watches for isolate scope and controller bindings. |
| 10715 | function initializeDirectiveBindings(scope, attrs, destination, bindings, directive) { |
| 10716 | var removeWatchCollection = []; |
| 10717 | var initialChanges = {}; |
| 10718 | var changes; |
| 10719 | |
| 10720 | forEach(bindings, function initializeBinding(definition, scopeName) { |
| 10721 | var attrName = definition.attrName, |
| 10722 | optional = definition.optional, |
| 10723 | mode = definition.mode, // @, =, <, or & |
| 10724 | lastValue, |
| 10725 | parentGet, parentSet, compare, removeWatch; |
| 10726 | |
| 10727 | switch (mode) { |
| 10728 | |
| 10729 | case '@': |
| 10730 | if (!optional && !hasOwnProperty.call(attrs, attrName)) { |
| 10731 | strictBindingsCheck(attrName, directive.name); |
| 10732 | destination[scopeName] = attrs[attrName] = undefined; |
| 10733 | |
| 10734 | } |
| 10735 | removeWatch = attrs.$observe(attrName, function(value) { |
| 10736 | if (isString(value) || isBoolean(value)) { |
| 10737 | var oldValue = destination[scopeName]; |
| 10738 | recordChanges(scopeName, value, oldValue); |
| 10739 | destination[scopeName] = value; |
| 10740 | } |
| 10741 | }); |
| 10742 | attrs.$$observers[attrName].$$scope = scope; |
| 10743 | lastValue = attrs[attrName]; |
| 10744 | if (isString(lastValue)) { |
| 10745 | // If the attribute has been provided then we trigger an interpolation to ensure |
| 10746 | // the value is there for use in the link fn |
| 10747 | destination[scopeName] = $interpolate(lastValue)(scope); |
| 10748 | } else if (isBoolean(lastValue)) { |
| 10749 | // If the attributes is one of the BOOLEAN_ATTR then AngularJS will have converted |
| 10750 | // the value to boolean rather than a string, so we special case this situation |
| 10751 | destination[scopeName] = lastValue; |
| 10752 | } |
| 10753 | initialChanges[scopeName] = new SimpleChange(_UNINITIALIZED_VALUE, destination[scopeName]); |
| 10754 | removeWatchCollection.push(removeWatch); |
| 10755 | break; |
| 10756 | |
| 10757 | case '=': |
| 10758 | if (!hasOwnProperty.call(attrs, attrName)) { |
| 10759 | if (optional) break; |
| 10760 | strictBindingsCheck(attrName, directive.name); |
| 10761 | attrs[attrName] = undefined; |
| 10762 | } |
| 10763 | if (optional && !attrs[attrName]) break; |
| 10764 | |
| 10765 | parentGet = $parse(attrs[attrName]); |
| 10766 | if (parentGet.literal) { |
| 10767 | compare = equals; |
| 10768 | } else { |
| 10769 | compare = simpleCompare; |
| 10770 | } |
| 10771 | parentSet = parentGet.assign || function() { |
| 10772 | // reset the change, or we will throw this exception on every $digest |
no test coverage detected