(scope, attrs, destination, bindings, directive)
| 11282 | |
| 11283 | // Set up $watches for isolate scope and controller bindings. |
| 11284 | function initializeDirectiveBindings(scope, attrs, destination, bindings, directive) { |
| 11285 | var removeWatchCollection = []; |
| 11286 | var initialChanges = {}; |
| 11287 | var changes; |
| 11288 | |
| 11289 | forEach(bindings, function initializeBinding(definition, scopeName) { |
| 11290 | var attrName = definition.attrName, |
| 11291 | optional = definition.optional, |
| 11292 | mode = definition.mode, // @, =, <, or & |
| 11293 | lastValue, |
| 11294 | parentGet, parentSet, compare, removeWatch; |
| 11295 | |
| 11296 | switch (mode) { |
| 11297 | |
| 11298 | case '@': |
| 11299 | if (!optional && !hasOwnProperty.call(attrs, attrName)) { |
| 11300 | strictBindingsCheck(attrName, directive.name); |
| 11301 | destination[scopeName] = attrs[attrName] = undefined; |
| 11302 | |
| 11303 | } |
| 11304 | removeWatch = attrs.$observe(attrName, function(value) { |
| 11305 | if (isString(value) || isBoolean(value)) { |
| 11306 | var oldValue = destination[scopeName]; |
| 11307 | recordChanges(scopeName, value, oldValue); |
| 11308 | destination[scopeName] = value; |
| 11309 | } |
| 11310 | }); |
| 11311 | attrs.$$observers[attrName].$$scope = scope; |
| 11312 | lastValue = attrs[attrName]; |
| 11313 | if (isString(lastValue)) { |
| 11314 | // If the attribute has been provided then we trigger an interpolation to ensure |
| 11315 | // the value is there for use in the link fn |
| 11316 | destination[scopeName] = $interpolate(lastValue)(scope); |
| 11317 | } else if (isBoolean(lastValue)) { |
| 11318 | // If the attributes is one of the BOOLEAN_ATTR then AngularJS will have converted |
| 11319 | // the value to boolean rather than a string, so we special case this situation |
| 11320 | destination[scopeName] = lastValue; |
| 11321 | } |
| 11322 | initialChanges[scopeName] = new SimpleChange(_UNINITIALIZED_VALUE, destination[scopeName]); |
| 11323 | removeWatchCollection.push(removeWatch); |
| 11324 | break; |
| 11325 | |
| 11326 | case '=': |
| 11327 | if (!hasOwnProperty.call(attrs, attrName)) { |
| 11328 | if (optional) break; |
| 11329 | strictBindingsCheck(attrName, directive.name); |
| 11330 | attrs[attrName] = undefined; |
| 11331 | } |
| 11332 | if (optional && !attrs[attrName]) break; |
| 11333 | |
| 11334 | parentGet = $parse(attrs[attrName]); |
| 11335 | if (parentGet.literal) { |
| 11336 | compare = equals; |
| 11337 | } else { |
| 11338 | compare = simpleCompare; |
| 11339 | } |
| 11340 | parentSet = parentGet.assign || function() { |
| 11341 | // reset the change, or we will throw this exception on every $digest |
no test coverage detected