MCPcopy
hub / github.com/angular-ui/ui-grid / initializeDirectiveBindings

Function initializeDirectiveBindings

lib/test/angular/1.8.0/angular.js:11349–11516  ·  view source on GitHub ↗
(scope, attrs, destination, bindings, directive)

Source from the content-addressed store, hash-verified

11347
11348 // Set up $watches for isolate scope and controller bindings.
11349 function initializeDirectiveBindings(scope, attrs, destination, bindings, directive) {
11350 var removeWatchCollection = [];
11351 var initialChanges = {};
11352 var changes;
11353
11354 forEach(bindings, function initializeBinding(definition, scopeName) {
11355 var attrName = definition.attrName,
11356 optional = definition.optional,
11357 mode = definition.mode, // @, =, <, or &
11358 lastValue,
11359 parentGet, parentSet, compare, removeWatch;
11360
11361 switch (mode) {
11362
11363 case '@':
11364 if (!optional && !hasOwnProperty.call(attrs, attrName)) {
11365 strictBindingsCheck(attrName, directive.name);
11366 destination[scopeName] = attrs[attrName] = undefined;
11367
11368 }
11369 removeWatch = attrs.$observe(attrName, function(value) {
11370 if (isString(value) || isBoolean(value)) {
11371 var oldValue = destination[scopeName];
11372 recordChanges(scopeName, value, oldValue);
11373 destination[scopeName] = value;
11374 }
11375 });
11376 attrs.$$observers[attrName].$$scope = scope;
11377 lastValue = attrs[attrName];
11378 if (isString(lastValue)) {
11379 // If the attribute has been provided then we trigger an interpolation to ensure
11380 // the value is there for use in the link fn
11381 destination[scopeName] = $interpolate(lastValue)(scope);
11382 } else if (isBoolean(lastValue)) {
11383 // If the attributes is one of the BOOLEAN_ATTR then AngularJS will have converted
11384 // the value to boolean rather than a string, so we special case this situation
11385 destination[scopeName] = lastValue;
11386 }
11387 initialChanges[scopeName] = new SimpleChange(_UNINITIALIZED_VALUE, destination[scopeName]);
11388 removeWatchCollection.push(removeWatch);
11389 break;
11390
11391 case '=':
11392 if (!hasOwnProperty.call(attrs, attrName)) {
11393 if (optional) break;
11394 strictBindingsCheck(attrName, directive.name);
11395 attrs[attrName] = undefined;
11396 }
11397 if (optional && !attrs[attrName]) break;
11398
11399 parentGet = $parse(attrs[attrName]);
11400 if (parentGet.literal) {
11401 compare = equals;
11402 } else {
11403 compare = simpleCompare;
11404 }
11405 parentSet = parentGet.assign || function() {
11406 // reset the change, or we will throw this exception on every $digest

Callers 1

nodeLinkFnFunction · 0.70

Calls 8

forEachFunction · 0.70
strictBindingsCheckFunction · 0.70
isStringFunction · 0.70
isBooleanFunction · 0.70
recordChangesFunction · 0.70
$interpolateFunction · 0.70
$parseFunction · 0.70
equalsFunction · 0.70

Tested by

no test coverage detected