diff options
| author | Igor Minar | 2013-11-07 16:19:03 -0800 | 
|---|---|---|
| committer | Igor Minar | 2013-11-07 22:08:22 -0800 | 
| commit | 27e9340b3c25b512e45213b39811098d07e12e3b (patch) | |
| tree | 63f817a20eea62f813fcf85ad40c1b8bcc6e1652 /src/jqLite.js | |
| parent | b5af198f0d5b0f2b3ddb31ea12f700f3e0616271 (diff) | |
| download | angular.js-27e9340b3c25b512e45213b39811098d07e12e3b.tar.bz2 | |
feat(jqLite): expose isolateScope() getter similar to scope()
See doc update in the diff for more info.
BREAKING CHANGE: jqLite#scope() does not return the isolate scope on the element
that triggered directive with isolate scope. Use jqLite#isolateScope() instead.
Diffstat (limited to 'src/jqLite.js')
| -rw-r--r-- | src/jqLite.js | 17 | 
1 files changed, 15 insertions, 2 deletions
| diff --git a/src/jqLite.js b/src/jqLite.js index 727218a9..218efe24 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -85,6 +85,9 @@   * - `injector()` - retrieves the injector of the current element or its parent.   * - `scope()` - retrieves the {@link api/ng.$rootScope.Scope scope} of the current   *   element or its parent. + * - `isolateScope()` - retrieves an isolate {@link api/ng.$rootScope.Scope scope} if one is attached directly to the + *   current element. This getter should be used only on elements that contain a directive which starts a new isolate + *   scope. Calling `scope()` on this element always returns the original non-isolate scope.   * - `inheritedData()` - same as `data()`, but walks up the DOM until a value is found or the top   *   parent element is reached.   * @@ -344,9 +347,13 @@ function jqLiteInheritedData(element, name, value) {    if(element[0].nodeType == 9) {      element = element.find('html');    } +  var names = isArray(name) ? name : [name];    while (element.length) { -    if ((value = element.data(name)) !== undefined) return value; + +    for (var i = 0, ii = names.length; i < ii; i++) { +      if ((value = element.data(names[i])) !== undefined) return value; +    }      element = element.parent();    }  } @@ -418,7 +425,13 @@ forEach({    inheritedData: jqLiteInheritedData,    scope: function(element) { -    return jqLiteInheritedData(element, '$scope'); +    // Can't use jqLiteData here directly so we stay compatible with jQuery! +    return jqLite(element).data('$scope') || jqLiteInheritedData(element.parentNode || element, ['$isolateScope', '$scope']); +  }, + +  isolateScope: function(element) { +    // Can't use jqLiteData here directly so we stay compatible with jQuery! +    return jqLite(element).data('$isolateScope') || jqLite(element).data('$isolateScopeNoTemplate');    },    controller: jqLiteController , | 
