(scope, attrs, destination, bindings, directive)
| 10624 | |
| 10625 | // Set up $watches for isolate scope and controller bindings. |
| 10626 | function initializeDirectiveBindings(scope, attrs, destination, bindings, directive) { |
| 10627 | var removeWatchCollection = []; |
| 10628 | var initialChanges = {}; |
| 10629 | var changes; |
| 10630 | |
| 10631 | forEach(bindings, function initializeBinding(definition, scopeName) { |
| 10632 | var attrName = definition.attrName, |
| 10633 | optional = definition.optional, |
| 10634 | mode = definition.mode, // @, =, <, or & |
| 10635 | lastValue, |
| 10636 | parentGet, parentSet, compare, removeWatch; |
| 10637 | |
| 10638 | switch (mode) { |
| 10639 | |
| 10640 | case '@': |
| 10641 | if (!optional && !hasOwnProperty.call(attrs, attrName)) { |
| 10642 | strictBindingsCheck(attrName, directive.name); |
| 10643 | destination[scopeName] = attrs[attrName] = undefined; |
| 10644 | |
| 10645 | } |
| 10646 | removeWatch = attrs.$observe(attrName, function(value) { |
| 10647 | if (isString(value) || isBoolean(value)) { |
| 10648 | var oldValue = destination[scopeName]; |
| 10649 | recordChanges(scopeName, value, oldValue); |
| 10650 | destination[scopeName] = value; |
| 10651 | } |
| 10652 | }); |
| 10653 | attrs.$$observers[attrName].$$scope = scope; |
| 10654 | lastValue = attrs[attrName]; |
| 10655 | if (isString(lastValue)) { |
| 10656 | // If the attribute has been provided then we trigger an interpolation to ensure |
| 10657 | // the value is there for use in the link fn |
| 10658 | destination[scopeName] = $interpolate(lastValue)(scope); |
| 10659 | } else if (isBoolean(lastValue)) { |
| 10660 | // If the attributes is one of the BOOLEAN_ATTR then Angular will have converted |
| 10661 | // the value to boolean rather than a string, so we special case this situation |
| 10662 | destination[scopeName] = lastValue; |
| 10663 | } |
| 10664 | initialChanges[scopeName] = new SimpleChange(_UNINITIALIZED_VALUE, destination[scopeName]); |
| 10665 | removeWatchCollection.push(removeWatch); |
| 10666 | break; |
| 10667 | |
| 10668 | case '=': |
| 10669 | if (!hasOwnProperty.call(attrs, attrName)) { |
| 10670 | if (optional) break; |
| 10671 | strictBindingsCheck(attrName, directive.name); |
| 10672 | attrs[attrName] = undefined; |
| 10673 | } |
| 10674 | if (optional && !attrs[attrName]) break; |
| 10675 | |
| 10676 | parentGet = $parse(attrs[attrName]); |
| 10677 | if (parentGet.literal) { |
| 10678 | compare = equals; |
| 10679 | } else { |
| 10680 | compare = simpleCompare; |
| 10681 | } |
| 10682 | parentSet = parentGet.assign || function() { |
| 10683 | // reset the change, or we will throw this exception on every $digest |
no test coverage detected