|
60 | 60 | *
|
61 | 61 | * ## In addtion to the above, Angular privides an additional method to both jQuery and jQuery lite:
|
62 | 62 | *
|
63 |
| - * - `scope()` - retrieves the current Angular scope of the element. |
64 |
| - * - `injector()` - retrieves the Angular injector associated with application that the element is |
65 |
| - * part of. |
| 63 | + * - `controller(name)` - retrieves the controller of the current element or its parent. By default |
| 64 | + * retrieves controller associated with the `ng-controller` directive. If `name` is provided as |
| 65 | + * camelCase directive name, then the controller for this directive will be retrieved (e.g. |
| 66 | + * `'ngModel'`). |
| 67 | + * - `injector()` - retrieves the injector of the current element or its parent. |
| 68 | + * - `scope()` - retrieves the {@link api/angular.module.ng.$rootScope.Scope scope} of the current |
| 69 | + * element or its parent. |
66 | 70 | * - `inheritedData()` - same as `data()`, but walks up the DOM until a value is found or the top
|
67 | 71 | * parent element is reached.
|
68 | 72 | *
|
@@ -268,6 +272,18 @@ function JQLiteAddNodes(root, elements) {
|
268 | 272 | }
|
269 | 273 | }
|
270 | 274 |
|
| 275 | +function JQLiteController(element, name) { |
| 276 | + return JQLiteInheritedData(element, '$' + (name || 'ngController' ) + 'Controller'); |
| 277 | +} |
| 278 | + |
| 279 | +function JQLiteInheritedData(element, name, value) { |
| 280 | + element = jqLite(element); |
| 281 | + while (element.length) { |
| 282 | + if (value = element.data(name)) return value; |
| 283 | + element = element.parent(); |
| 284 | + } |
| 285 | +} |
| 286 | + |
271 | 287 | //////////////////////////////////////////
|
272 | 288 | // Functions which are declared directly.
|
273 | 289 | //////////////////////////////////////////
|
@@ -321,20 +337,16 @@ function isBooleanAttr(element, name) {
|
321 | 337 |
|
322 | 338 | forEach({
|
323 | 339 | data: JQLiteData,
|
324 |
| - inheritedData: function(element, name, value) { |
325 |
| - element = jqLite(element); |
326 |
| - while (element.length) { |
327 |
| - if (value = element.data(name)) return value; |
328 |
| - element = element.parent(); |
329 |
| - } |
330 |
| - }, |
| 340 | + inheritedData: JQLiteInheritedData, |
331 | 341 |
|
332 | 342 | scope: function(element) {
|
333 |
| - return jqLite(element).inheritedData('$scope'); |
| 343 | + return JQLiteInheritedData(element, '$scope'); |
334 | 344 | },
|
335 | 345 |
|
| 346 | + controller: JQLiteController , |
| 347 | + |
336 | 348 | injector: function(element) {
|
337 |
| - return jqLite(element).inheritedData('$injector'); |
| 349 | + return JQLiteInheritedData(element, '$injector'); |
338 | 350 | },
|
339 | 351 |
|
340 | 352 | removeAttr: function(element,name) {
|
@@ -449,7 +461,7 @@ forEach({
|
449 | 461 |
|
450 | 462 | // JQLiteHasClass has only two arguments, but is a getter-only fn, so we need to special-case it
|
451 | 463 | // in a way that survives minification.
|
452 |
| - if (((fn.length == 2 && fn !== JQLiteHasClass) ? arg1 : arg2) === undefined) { |
| 464 | + if (((fn.length == 2 && (fn !== JQLiteHasClass && fn !== JQLiteController)) ? arg1 : arg2) === undefined) { |
453 | 465 | if (isObject(arg1)) {
|
454 | 466 | // we are a write, but the object properties are the key/values
|
455 | 467 | for(i=0; i < this.length; i++) {
|
|
0 commit comments