(scope, attrs, destination, bindings, directive)
| 10158 | |
| 10159 | // Set up $watches for isolate scope and controller bindings. |
| 10160 | function initializeDirectiveBindings(scope, attrs, destination, bindings, directive) { |
| 10161 | var removeWatchCollection = []; |
| 10162 | var initialChanges = {}; |
| 10163 | var changes; |
| 10164 | forEach(bindings, function initializeBinding(definition, scopeName) { |
| 10165 | var attrName = definition.attrName, |
| 10166 | optional = definition.optional, |
| 10167 | mode = definition.mode, // @, =, <, or & |
| 10168 | lastValue, |
| 10169 | parentGet, parentSet, compare, removeWatch; |
| 10170 | |
| 10171 | switch (mode) { |
| 10172 | |
| 10173 | case '@': |
| 10174 | if (!optional && !hasOwnProperty.call(attrs, attrName)) { |
| 10175 | destination[scopeName] = attrs[attrName] = undefined; |
| 10176 | } |
| 10177 | removeWatch = attrs.$observe(attrName, function(value) { |
| 10178 | if (isString(value) || isBoolean(value)) { |
| 10179 | var oldValue = destination[scopeName]; |
| 10180 | recordChanges(scopeName, value, oldValue); |
| 10181 | destination[scopeName] = value; |
| 10182 | } |
| 10183 | }); |
| 10184 | attrs.$$observers[attrName].$$scope = scope; |
| 10185 | lastValue = attrs[attrName]; |
| 10186 | if (isString(lastValue)) { |
| 10187 | // If the attribute has been provided then we trigger an interpolation to ensure |
| 10188 | // the value is there for use in the link fn |
| 10189 | destination[scopeName] = $interpolate(lastValue)(scope); |
| 10190 | } else if (isBoolean(lastValue)) { |
| 10191 | // If the attributes is one of the BOOLEAN_ATTR then Angular will have converted |
| 10192 | // the value to boolean rather than a string, so we special case this situation |
| 10193 | destination[scopeName] = lastValue; |
| 10194 | } |
| 10195 | initialChanges[scopeName] = new SimpleChange(_UNINITIALIZED_VALUE, destination[scopeName]); |
| 10196 | removeWatchCollection.push(removeWatch); |
| 10197 | break; |
| 10198 | |
| 10199 | case '=': |
| 10200 | if (!hasOwnProperty.call(attrs, attrName)) { |
| 10201 | if (optional) break; |
| 10202 | attrs[attrName] = undefined; |
| 10203 | } |
| 10204 | if (optional && !attrs[attrName]) break; |
| 10205 | |
| 10206 | parentGet = $parse(attrs[attrName]); |
| 10207 | if (parentGet.literal) { |
| 10208 | compare = equals; |
| 10209 | } else { |
| 10210 | // eslint-disable-next-line no-self-compare |
| 10211 | compare = function simpleCompare(a, b) { return a === b || (a !== a && b !== b); }; |
| 10212 | } |
| 10213 | parentSet = parentGet.assign || function() { |
| 10214 | // reset the change, or we will throw this exception on every $digest |
| 10215 | lastValue = destination[scopeName] = parentGet(scope); |
| 10216 | throw $compileMinErr('nonassign', |
| 10217 | 'Expression \'{0}\' in attribute \'{1}\' used with directive \'{2}\' is non-assignable!', |
no test coverage detected