* @ngdoc function * @name angular.bootstrap * @module ng * @description * Use this function to manually start up angular application. * * See: guide/bootstrap Bootstrap * * Note that Protractor based end-to-end tests cannot use this function to bootstr
(element, modules, config)
| 1625 | * @returns {auto.$injector} Returns the newly created injector for this app. |
| 1626 | */ |
| 1627 | function bootstrap(element, modules, config) { |
| 1628 | if (!isObject(config)) config = {}; |
| 1629 | var defaultConfig = { |
| 1630 | strictDi: false |
| 1631 | }; |
| 1632 | config = extend(defaultConfig, config); |
| 1633 | var doBootstrap = function () { |
| 1634 | element = jqLite(element); |
| 1635 | |
| 1636 | if (element.injector()) { |
| 1637 | var tag = (element[0] === document) ? 'document' : startingTag(element); |
| 1638 | //Encode angle brackets to prevent input from being sanitized to empty string #8683 |
| 1639 | throw ngMinErr( |
| 1640 | 'btstrpd', |
| 1641 | "App Already Bootstrapped with this Element '{0}'", |
| 1642 | tag.replace(/</, '<').replace(/>/, '>')); |
| 1643 | } |
| 1644 | |
| 1645 | modules = modules || []; |
| 1646 | modules.unshift([ |
| 1647 | '$provide', function ($provide) { |
| 1648 | $provide.value('$rootElement', element); |
| 1649 | } |
| 1650 | ]); |
| 1651 | |
| 1652 | if (config.debugInfoEnabled) { |
| 1653 | // Pushing so that this overrides `debugInfoEnabled` setting defined in user's `modules`. |
| 1654 | modules.push([ |
| 1655 | '$compileProvider', function ($compileProvider) { |
| 1656 | $compileProvider.debugInfoEnabled(true); |
| 1657 | } |
| 1658 | ]); |
| 1659 | } |
| 1660 | |
| 1661 | modules.unshift('ng'); |
| 1662 | var injector = createInjector(modules, config.strictDi); |
| 1663 | injector.invoke([ |
| 1664 | '$rootScope', '$rootElement', '$compile', '$injector', |
| 1665 | function bootstrapApply(scope, element, compile, injector) { |
| 1666 | scope.$apply(function () { |
| 1667 | element.data('$injector', injector); |
| 1668 | compile(element)(scope); |
| 1669 | }); |
| 1670 | } |
| 1671 | ] |
| 1672 | ); |
| 1673 | return injector; |
| 1674 | }; |
| 1675 | |
| 1676 | var NG_ENABLE_DEBUG_INFO = /^NG_ENABLE_DEBUG_INFO!/; |
| 1677 | var NG_DEFER_BOOTSTRAP = /^NG_DEFER_BOOTSTRAP!/; |
| 1678 | |
| 1679 | if (window && NG_ENABLE_DEBUG_INFO.test(window.name)) { |
| 1680 | config.debugInfoEnabled = true; |
| 1681 | window.name = window.name.replace(NG_ENABLE_DEBUG_INFO, ''); |
| 1682 | } |
| 1683 | |
| 1684 | if (window && !NG_DEFER_BOOTSTRAP.test(window.name)) { |
no test coverage detected