angular-es-utils
Advanced tools
Comparing version 1.2.14 to 1.2.15
@@ -6,2 +6,3 @@ 'use strict'; | ||
}); | ||
exports.getInjector = getInjector; | ||
@@ -14,16 +15,39 @@ var _angular = require('angular'); | ||
var injector = null; /** | ||
* @author Kuitos | ||
* @homepage https://github.com/kuitos/ | ||
* @since 2016-04-25 | ||
*/ | ||
var injector = null; | ||
var bootstrap = _angular2.default.bootstrap; | ||
/** | ||
* 获取应用的injector,默认查询被ng-app标记的节点,否则从document.body开始找 | ||
* @param rootElement | ||
*/ | ||
/** | ||
* @author Kuitos | ||
* @homepage https://github.com/kuitos/ | ||
* @since 2016-04-25 | ||
*/ | ||
// rewrite angular bootstrap method to assign our injector | ||
_angular2.default.bootstrap = function () { | ||
injector = bootstrap.apply(undefined, arguments); | ||
return injector; | ||
}; | ||
function getInjector() { | ||
var rootElement = arguments.length <= 0 || arguments[0] === undefined ? document.querySelector('[ng-app]') || document.body : arguments[0]; | ||
var injector = _angular2.default.element(rootElement).injector(); | ||
if (injector) { | ||
return injector; | ||
} else { | ||
var childNodes = rootElement.childNodes; | ||
for (var i = 0; i < childNodes.length; i++) { | ||
var _injector = getInjector(childNodes[i]); | ||
if (_injector) { | ||
return _injector; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
// make commonjs have the same behavior with es6 module | ||
@@ -35,3 +59,3 @@ Object.defineProperty(exports, 'default', { | ||
get: function get() { | ||
return injector; | ||
return injector || getInjector(); | ||
} | ||
@@ -38,0 +62,0 @@ }); |
{ | ||
"name": "angular-es-utils", | ||
"version": "1.2.14", | ||
"version": "1.2.15", | ||
"description": "es utils design for angular1.x", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
18188
443