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 | |
| 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')
| -rw-r--r-- | src/Angular.js | 1 | ||||
| -rw-r--r-- | src/jqLite.js | 17 | ||||
| -rw-r--r-- | src/ng/compile.js | 12 |
3 files changed, 26 insertions, 4 deletions
diff --git a/src/Angular.js b/src/Angular.js index 55a9bd8d..93fccd04 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -1244,6 +1244,7 @@ function bindJQuery() { jqLite = jQuery; extend(jQuery.fn, { scope: JQLitePrototype.scope, + isolateScope: JQLitePrototype.isolateScope, controller: JQLitePrototype.controller, injector: JQLitePrototype.injector, inheritedData: JQLitePrototype.inheritedData 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 , diff --git a/src/ng/compile.js b/src/ng/compile.js index 7513fc7e..2e3d7867 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1368,7 +1368,15 @@ function $CompileProvider($provide) { var $linkNode = jqLite(linkNode); isolateScope = scope.$new(true); - $linkNode.data('$isolateScope', isolateScope); + + if (templateDirective && (templateDirective === newIsolateScopeDirective.$$originalDirective)) { + $linkNode.data('$isolateScope', isolateScope) ; + } else { + $linkNode.data('$isolateScopeNoTemplate', isolateScope); + } + + + safeAddClass($linkNode, 'ng-isolate-scope'); forEach(newIsolateScopeDirective.scope, function(definition, scopeName) { @@ -1600,7 +1608,7 @@ function $CompileProvider($provide) { origAsyncDirective = directives.shift(), // The fact that we have to copy and patch the directive seems wrong! derivedSyncDirective = extend({}, origAsyncDirective, { - templateUrl: null, transclude: null, replace: null + templateUrl: null, transclude: null, replace: null, $$originalDirective: origAsyncDirective }), templateUrl = (isFunction(origAsyncDirective.templateUrl)) ? origAsyncDirective.templateUrl($compileNode, tAttrs) |
