* @ngdoc function * @name angular.bootstrap * @module ng * @description * Use this function to manually start up AngularJS application. * * For more information, see the guide/bootstrap Bootstrap guide. * * AngularJS will detect if it has been loaded into the browser more than once a
(element, modules, config)
| 1890 | * @returns {auto.$injector} Returns the newly created injector for this app. |
| 1891 | */ |
| 1892 | function bootstrap(element, modules, config) { |
| 1893 | if (!isObject(config)) config = {}; |
| 1894 | var defaultConfig = { |
| 1895 | strictDi: false |
| 1896 | }; |
| 1897 | config = extend(defaultConfig, config); |
| 1898 | var doBootstrap = function() { |
| 1899 | element = jqLite(element); |
| 1900 | |
| 1901 | if (element.injector()) { |
| 1902 | var tag = (element[0] === window.document) ? 'document' : startingTag(element); |
| 1903 | // Encode angle brackets to prevent input from being sanitized to empty string #8683. |
| 1904 | throw ngMinErr( |
| 1905 | 'btstrpd', |
| 1906 | 'App already bootstrapped with this element \'{0}\'', |
| 1907 | tag.replace(/</,'<').replace(/>/,'>')); |
| 1908 | } |
| 1909 | |
| 1910 | modules = modules || []; |
| 1911 | modules.unshift(['$provide', function($provide) { |
| 1912 | $provide.value('$rootElement', element); |
| 1913 | }]); |
| 1914 | |
| 1915 | if (config.debugInfoEnabled) { |
| 1916 | // Pushing so that this overrides `debugInfoEnabled` setting defined in user's `modules`. |
| 1917 | modules.push(['$compileProvider', function($compileProvider) { |
| 1918 | $compileProvider.debugInfoEnabled(true); |
| 1919 | }]); |
| 1920 | } |
| 1921 | |
| 1922 | modules.unshift('ng'); |
| 1923 | var injector = createInjector(modules, config.strictDi); |
| 1924 | injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector', |
| 1925 | function bootstrapApply(scope, element, compile, injector) { |
| 1926 | scope.$apply(function() { |
| 1927 | element.data('$injector', injector); |
| 1928 | compile(element)(scope); |
| 1929 | }); |
| 1930 | }] |
| 1931 | ); |
| 1932 | return injector; |
| 1933 | }; |
| 1934 | |
| 1935 | var NG_ENABLE_DEBUG_INFO = /^NG_ENABLE_DEBUG_INFO!/; |
| 1936 | var NG_DEFER_BOOTSTRAP = /^NG_DEFER_BOOTSTRAP!/; |
| 1937 | |
| 1938 | if (window && NG_ENABLE_DEBUG_INFO.test(window.name)) { |
| 1939 | config.debugInfoEnabled = true; |
| 1940 | window.name = window.name.replace(NG_ENABLE_DEBUG_INFO, ''); |
| 1941 | } |
| 1942 | |
| 1943 | if (window && !NG_DEFER_BOOTSTRAP.test(window.name)) { |
| 1944 | return doBootstrap(); |
| 1945 | } |
| 1946 | |
| 1947 | window.name = window.name.replace(NG_DEFER_BOOTSTRAP, ''); |
| 1948 | angular.resumeBootstrap = function(extraModules) { |
| 1949 | forEach(extraModules, function(module) { |
no test coverage detected