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