mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
feat(jqLite): added injector() helper method
This commit is contained in:
parent
c49b8a2db5
commit
b587091b6e
3 changed files with 20 additions and 0 deletions
|
|
@ -923,6 +923,7 @@ function bindJQuery() {
|
|||
jqLite = jQuery;
|
||||
extend(jQuery.fn, {
|
||||
scope: JQLitePrototype.scope,
|
||||
injector: JQLitePrototype.injector,
|
||||
inheritedData: JQLitePrototype.inheritedData
|
||||
});
|
||||
JQLitePatchJQueryRemove('remove', true);
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@
|
|||
* ## In addtion to the above, Angular privides an additional method to both jQuery and jQuery lite:
|
||||
*
|
||||
* - `scope()` - retrieves the current Angular scope of the element.
|
||||
* - `injector()` - retrieves the Angular injector associated with application that the element is
|
||||
* part of.
|
||||
* - `inheritedData()` - same as `data()`, but walks up the DOM until a value is found or the top
|
||||
* parent element is reached.
|
||||
*
|
||||
|
|
@ -314,6 +316,10 @@ forEach({
|
|||
return jqLite(element).inheritedData($$scope);
|
||||
},
|
||||
|
||||
injector: function(element) {
|
||||
return jqLite(element).inheritedData('$injector');
|
||||
},
|
||||
|
||||
removeAttr: function(element,name) {
|
||||
element.removeAttribute(name);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -138,6 +138,19 @@ describe('jqLite', function() {
|
|||
});
|
||||
|
||||
|
||||
describe('injector', function() {
|
||||
it('should retrieve injector attached to the current element or its parent', function() {
|
||||
var template = jqLite('<div><span></span></div>'),
|
||||
span = template.children().eq(0),
|
||||
injector = angular.bootstrap(template);
|
||||
|
||||
|
||||
expect(span.injector()).toBe(injector);
|
||||
dealoc(template);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('data', function() {
|
||||
it('should set and get and remove data', function() {
|
||||
var selected = jqLite([a, b, c]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue