2016-06-23 16:47:54 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
2020-05-19 19:08:49 +00:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-06-23 16:47:54 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
2024-09-20 15:23:15 +00:00
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
2016-06-23 16:47:54 +00:00
|
|
|
*/
|
|
|
|
|
|
2021-03-23 09:28:54 +00:00
|
|
|
import {
|
|
|
|
|
CommonModule,
|
|
|
|
|
DOCUMENT,
|
|
|
|
|
XhrFactory,
|
|
|
|
|
ɵPLATFORM_BROWSER_ID as PLATFORM_BROWSER_ID,
|
|
|
|
|
} from '@angular/common';
|
2023-03-07 07:25:19 +00:00
|
|
|
import {
|
|
|
|
|
ApplicationConfig as ApplicationConfigFromCore,
|
|
|
|
|
ApplicationModule,
|
|
|
|
|
ApplicationRef,
|
|
|
|
|
createPlatformFactory,
|
|
|
|
|
ErrorHandler,
|
|
|
|
|
InjectionToken,
|
|
|
|
|
NgModule,
|
|
|
|
|
NgZone,
|
|
|
|
|
PLATFORM_ID,
|
|
|
|
|
PLATFORM_INITIALIZER,
|
|
|
|
|
platformCore,
|
|
|
|
|
PlatformRef,
|
|
|
|
|
Provider,
|
|
|
|
|
RendererFactory2,
|
|
|
|
|
StaticProvider,
|
|
|
|
|
Testability,
|
|
|
|
|
TestabilityRegistry,
|
|
|
|
|
Type,
|
|
|
|
|
ɵINJECTOR_SCOPE as INJECTOR_SCOPE,
|
|
|
|
|
ɵinternalCreateApplication as internalCreateApplication,
|
|
|
|
|
ɵRuntimeError as RuntimeError,
|
|
|
|
|
ɵsetDocument,
|
|
|
|
|
ɵTESTABILITY as TESTABILITY,
|
|
|
|
|
ɵTESTABILITY_GETTER as TESTABILITY_GETTER,
|
2025-01-07 17:18:57 +00:00
|
|
|
inject,
|
2023-03-07 07:25:19 +00:00
|
|
|
} from '@angular/core';
|
2020-04-13 23:40:21 +00:00
|
|
|
|
2016-06-08 23:38:52 +00:00
|
|
|
import {BrowserDomAdapter} from './browser/browser_adapter';
|
|
|
|
|
import {BrowserGetTestability} from './browser/testability';
|
2021-03-23 09:28:54 +00:00
|
|
|
import {BrowserXhr} from './browser/xhr';
|
2023-03-15 07:14:58 +00:00
|
|
|
import {DomRendererFactory2} from './dom/dom_renderer';
|
2016-06-08 23:38:52 +00:00
|
|
|
import {DomEventsPlugin} from './dom/events/dom_events';
|
2018-08-03 19:30:40 +00:00
|
|
|
import {EVENT_MANAGER_PLUGINS, EventManager} from './dom/events/event_manager';
|
2016-06-08 23:38:52 +00:00
|
|
|
import {KeyEventsPlugin} from './dom/events/key_events';
|
2023-03-20 08:11:02 +00:00
|
|
|
import {SharedStylesHost} from './dom/shared_styles_host';
|
2023-03-07 07:25:19 +00:00
|
|
|
import {RuntimeErrorCode} from './errors';
|
2022-04-21 02:31:35 +00:00
|
|
|
|
|
|
|
|
/**
|
2022-07-06 07:18:29 +00:00
|
|
|
* Set of config options available during the application bootstrap operation.
|
2022-04-21 02:31:35 +00:00
|
|
|
*
|
|
|
|
|
* @publicApi
|
2023-02-28 11:21:05 +00:00
|
|
|
*
|
|
|
|
|
* @deprecated
|
|
|
|
|
* `ApplicationConfig` has moved, please import `ApplicationConfig` from `@angular/core` instead.
|
2022-04-21 02:31:35 +00:00
|
|
|
*/
|
2023-02-28 11:21:05 +00:00
|
|
|
// The below is a workaround to add a deprecated message.
|
|
|
|
|
type ApplicationConfig = ApplicationConfigFromCore;
|
|
|
|
|
export {ApplicationConfig};
|
2022-04-21 02:31:35 +00:00
|
|
|
|
|
|
|
|
/**
|
2022-05-31 23:26:16 +00:00
|
|
|
* Bootstraps an instance of an Angular application and renders a standalone component as the
|
|
|
|
|
* application's root component. More information about standalone components can be found in [this
|
2024-03-26 06:37:31 +00:00
|
|
|
* guide](guide/components/importing).
|
2022-04-21 02:31:35 +00:00
|
|
|
*
|
2022-05-31 23:26:16 +00:00
|
|
|
* @usageNotes
|
|
|
|
|
* The root component passed into this function *must* be a standalone one (should have the
|
2022-04-21 02:31:35 +00:00
|
|
|
* `standalone: true` flag in the `@Component` decorator config).
|
|
|
|
|
*
|
2024-12-03 14:59:35 +00:00
|
|
|
* ```angular-ts
|
2022-04-21 02:31:35 +00:00
|
|
|
* @Component({
|
|
|
|
|
* standalone: true,
|
|
|
|
|
* template: 'Hello world!'
|
|
|
|
|
* })
|
|
|
|
|
* class RootComponent {}
|
|
|
|
|
*
|
|
|
|
|
* const appRef: ApplicationRef = await bootstrapApplication(RootComponent);
|
|
|
|
|
* ```
|
|
|
|
|
*
|
2022-05-31 23:26:16 +00:00
|
|
|
* You can add the list of providers that should be available in the application injector by
|
|
|
|
|
* specifying the `providers` field in an object passed as the second argument:
|
|
|
|
|
*
|
2024-12-03 14:59:35 +00:00
|
|
|
* ```ts
|
2022-05-31 23:26:16 +00:00
|
|
|
* await bootstrapApplication(RootComponent, {
|
|
|
|
|
* providers: [
|
|
|
|
|
* {provide: BACKEND_URL, useValue: 'https://yourdomain.com/api'}
|
|
|
|
|
* ]
|
|
|
|
|
* });
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* The `importProvidersFrom` helper method can be used to collect all providers from any
|
|
|
|
|
* existing NgModule (and transitively from all NgModules that it imports):
|
|
|
|
|
*
|
2024-12-03 14:59:35 +00:00
|
|
|
* ```ts
|
2022-05-31 23:26:16 +00:00
|
|
|
* await bootstrapApplication(RootComponent, {
|
|
|
|
|
* providers: [
|
|
|
|
|
* importProvidersFrom(SomeNgModule)
|
|
|
|
|
* ]
|
|
|
|
|
* });
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* Note: the `bootstrapApplication` method doesn't include [Testability](api/core/Testability) by
|
|
|
|
|
* default. You can add [Testability](api/core/Testability) by getting the list of necessary
|
|
|
|
|
* providers using `provideProtractorTestingSupport()` function and adding them into the `providers`
|
|
|
|
|
* array, for example:
|
2022-05-05 01:01:14 +00:00
|
|
|
*
|
2024-12-03 14:59:35 +00:00
|
|
|
* ```ts
|
2022-05-05 01:01:14 +00:00
|
|
|
* import {provideProtractorTestingSupport} from '@angular/platform-browser';
|
|
|
|
|
*
|
2022-05-31 23:26:16 +00:00
|
|
|
* await bootstrapApplication(RootComponent, {providers: [provideProtractorTestingSupport()]});
|
2022-05-05 01:01:14 +00:00
|
|
|
* ```
|
|
|
|
|
*
|
2022-05-31 23:26:16 +00:00
|
|
|
* @param rootComponent A reference to a standalone component that should be rendered.
|
|
|
|
|
* @param options Extra configuration for the bootstrap operation, see `ApplicationConfig` for
|
2022-04-21 02:31:35 +00:00
|
|
|
* additional info.
|
|
|
|
|
* @returns A promise that returns an `ApplicationRef` instance once resolved.
|
|
|
|
|
*
|
|
|
|
|
* @publicApi
|
|
|
|
|
*/
|
|
|
|
|
export function bootstrapApplication(
|
|
|
|
|
rootComponent: Type<unknown>,
|
|
|
|
|
options?: ApplicationConfig,
|
|
|
|
|
): Promise<ApplicationRef> {
|
2022-07-06 07:18:29 +00:00
|
|
|
return internalCreateApplication({rootComponent, ...createProvidersConfig(options)});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create an instance of an Angular application without bootstrapping any components. This is useful
|
|
|
|
|
* for the situation where one wants to decouple application environment creation (a platform and
|
|
|
|
|
* associated injectors) from rendering components on a screen. Components can be subsequently
|
|
|
|
|
* bootstrapped on the returned `ApplicationRef`.
|
|
|
|
|
*
|
|
|
|
|
* @param options Extra configuration for the application environment, see `ApplicationConfig` for
|
|
|
|
|
* additional info.
|
|
|
|
|
* @returns A promise that returns an `ApplicationRef` instance once resolved.
|
|
|
|
|
*
|
|
|
|
|
* @publicApi
|
|
|
|
|
*/
|
|
|
|
|
export function createApplication(options?: ApplicationConfig) {
|
|
|
|
|
return internalCreateApplication(createProvidersConfig(options));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createProvidersConfig(options?: ApplicationConfig) {
|
|
|
|
|
return {
|
2022-04-21 02:31:35 +00:00
|
|
|
appProviders: [...BROWSER_MODULE_PROVIDERS, ...(options?.providers ?? [])],
|
2022-07-06 07:18:29 +00:00
|
|
|
platformProviders: INTERNAL_BROWSER_PLATFORM_PROVIDERS,
|
|
|
|
|
};
|
2022-04-21 02:31:35 +00:00
|
|
|
}
|
2016-05-20 23:11:49 +00:00
|
|
|
|
2022-05-05 01:01:14 +00:00
|
|
|
/**
|
|
|
|
|
* Returns a set of providers required to setup [Testability](api/core/Testability) for an
|
|
|
|
|
* application bootstrapped using the `bootstrapApplication` function. The set of providers is
|
|
|
|
|
* needed to support testing an application with Protractor (which relies on the Testability APIs
|
|
|
|
|
* to be present).
|
|
|
|
|
*
|
|
|
|
|
* @returns An array of providers required to setup Testability for an application and make it
|
|
|
|
|
* available for testing using Protractor.
|
|
|
|
|
*
|
|
|
|
|
* @publicApi
|
|
|
|
|
*/
|
|
|
|
|
export function provideProtractorTestingSupport(): Provider[] {
|
|
|
|
|
// Return a copy to prevent changes to the original array in case any in-place
|
2023-02-28 11:21:05 +00:00
|
|
|
// alterations are performed to the `provideProtractorTestingSupport` call results in app
|
|
|
|
|
// code.
|
2022-05-05 01:01:14 +00:00
|
|
|
return [...TESTABILITY_PROVIDERS];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 01:19:30 +00:00
|
|
|
export function initDomAdapter() {
|
|
|
|
|
BrowserDomAdapter.makeCurrent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function errorHandler(): ErrorHandler {
|
|
|
|
|
return new ErrorHandler();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function _document(): any {
|
|
|
|
|
// Tell ivy about the global document
|
|
|
|
|
ɵsetDocument(document);
|
|
|
|
|
return document;
|
|
|
|
|
}
|
|
|
|
|
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 19:33:29 +00:00
|
|
|
export const INTERNAL_BROWSER_PLATFORM_PROVIDERS: StaticProvider[] = [
|
2017-02-23 00:49:46 +00:00
|
|
|
{provide: PLATFORM_ID, useValue: PLATFORM_BROWSER_ID},
|
2016-07-18 10:50:31 +00:00
|
|
|
{provide: PLATFORM_INITIALIZER, useValue: initDomAdapter, multi: true},
|
2017-02-15 00:14:40 +00:00
|
|
|
{provide: DOCUMENT, useFactory: _document, deps: []},
|
2016-07-18 10:50:31 +00:00
|
|
|
];
|
2016-05-20 23:11:49 +00:00
|
|
|
|
2018-10-19 13:37:01 +00:00
|
|
|
/**
|
2020-05-18 18:45:49 +00:00
|
|
|
* A factory function that returns a `PlatformRef` instance associated with browser service
|
|
|
|
|
* providers.
|
|
|
|
|
*
|
2018-10-19 13:37:01 +00:00
|
|
|
* @publicApi
|
|
|
|
|
*/
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 19:33:29 +00:00
|
|
|
export const platformBrowser: (extraProviders?: StaticProvider[]) => PlatformRef =
|
2016-07-26 12:21:19 +00:00
|
|
|
createPlatformFactory(platformCore, 'browser', INTERNAL_BROWSER_PLATFORM_PROVIDERS);
|
|
|
|
|
|
2022-04-30 02:06:36 +00:00
|
|
|
/**
|
|
|
|
|
* Internal marker to signal whether providers from the `BrowserModule` are already present in DI.
|
|
|
|
|
* This is needed to avoid loading `BrowserModule` providers twice. We can't rely on the
|
|
|
|
|
* `BrowserModule` presence itself, since the standalone-based bootstrap just imports
|
|
|
|
|
* `BrowserModule` providers without referencing the module itself.
|
|
|
|
|
*/
|
2023-03-22 02:52:50 +00:00
|
|
|
const BROWSER_MODULE_PROVIDERS_MARKER = new InjectionToken(
|
|
|
|
|
typeof ngDevMode === 'undefined' || ngDevMode ? 'BrowserModule Providers Marker' : '',
|
|
|
|
|
);
|
2022-04-30 02:06:36 +00:00
|
|
|
|
2022-05-05 01:01:14 +00:00
|
|
|
const TESTABILITY_PROVIDERS = [
|
2022-04-16 01:29:11 +00:00
|
|
|
{
|
|
|
|
|
provide: TESTABILITY_GETTER,
|
|
|
|
|
useClass: BrowserGetTestability,
|
|
|
|
|
deps: [],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
provide: TESTABILITY,
|
|
|
|
|
useClass: Testability,
|
|
|
|
|
deps: [NgZone, TestabilityRegistry, TESTABILITY_GETTER],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
provide: Testability, // Also provide as `Testability` for backwards-compatibility.
|
|
|
|
|
useClass: Testability,
|
|
|
|
|
deps: [NgZone, TestabilityRegistry, TESTABILITY_GETTER],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2022-05-05 01:01:14 +00:00
|
|
|
const BROWSER_MODULE_PROVIDERS: Provider[] = [
|
2019-08-23 02:19:41 +00:00
|
|
|
{provide: INJECTOR_SCOPE, useValue: 'root'},
|
2022-04-30 02:06:36 +00:00
|
|
|
{provide: ErrorHandler, useFactory: errorHandler, deps: []},
|
|
|
|
|
{
|
2018-05-09 23:49:39 +00:00
|
|
|
provide: EVENT_MANAGER_PLUGINS,
|
|
|
|
|
useClass: DomEventsPlugin,
|
|
|
|
|
multi: true,
|
2025-01-30 21:53:56 +00:00
|
|
|
deps: [DOCUMENT],
|
2018-05-09 23:49:39 +00:00
|
|
|
},
|
2023-03-15 07:14:58 +00:00
|
|
|
{provide: EVENT_MANAGER_PLUGINS, useClass: KeyEventsPlugin, multi: true, deps: [DOCUMENT]},
|
|
|
|
|
DomRendererFactory2,
|
|
|
|
|
SharedStylesHost,
|
|
|
|
|
EventManager,
|
2018-05-09 23:49:39 +00:00
|
|
|
{provide: RendererFactory2, useExisting: DomRendererFactory2},
|
2021-03-23 09:28:54 +00:00
|
|
|
{provide: XhrFactory, useClass: BrowserXhr, deps: []},
|
2023-03-22 02:52:50 +00:00
|
|
|
typeof ngDevMode === 'undefined' || ngDevMode
|
|
|
|
|
? {provide: BROWSER_MODULE_PROVIDERS_MARKER, useValue: true}
|
|
|
|
|
: [],
|
2018-05-09 23:49:39 +00:00
|
|
|
];
|
|
|
|
|
|
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 20:07:17 +00:00
|
|
|
/**
|
2018-08-22 15:52:19 +00:00
|
|
|
* Exports required infrastructure for all Angular apps.
|
2019-02-18 21:02:54 +00:00
|
|
|
* Included by default in all Angular apps created with the CLI
|
2018-08-22 15:52:19 +00:00
|
|
|
* `new` command.
|
|
|
|
|
* Re-exports `CommonModule` and `ApplicationModule`, making their
|
|
|
|
|
* exports and providers available to all apps.
|
refactor(core): clean up platform bootstrap and initTestEnvironment
- Introduces `CompilerFactory` which can be part of a `PlatformRef`.
- Introduces `WorkerAppModule`, `WorkerUiModule`, `ServerModule`
- Introduces `serverDynamicPlatform` for applications using runtime compilation
on the server.
- Changes browser bootstrap for runtime and offline compilation (see below for an example).
* introduces `bootstrapModule` and `bootstrapModuleFactory` in `@angular/core`
* introduces new `browserDynamicPlatform` in `@angular/platform-browser-dynamic
- Changes `initTestEnvironment` (which used to be `setBaseTestProviders`) to not take a compiler factory any more (see below for an example).
BREAKING CHANGE:
## Migration from `setBaseTestProviders` to `initTestEnvironment`:
- For the browser platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
```
AFTER:
```
import {initTestEnvironment} from ‘@angular/core/testing’;
import {browserDynamicTestPlatform,
BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
BrowserDynamicTestModule,
browserDynamicTestPlatform());
```
- For the server platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS);
```
AFTER:
```
import {initTestEnvironment} from ‘@angular/core/testing’;
import {serverTestPlatform,
ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
ServerTestModule,
serverTestPlatform());
```
## Bootstrap changes
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {browserPlatform} from ‘@angular/platform-browser’;
import {bootstrapModuleFactory} from ‘@angular/core’;
bootstrapModuleFactory(MyModuleNgFactory, browserPlatform());
// runtime compile long form
import {browserDynamicPlatform} from ‘@angular/platform-browser-dynamic’;
import {bootstrapModule} from ‘@angular/core’;
bootstrapModule(MyModule, browserDynamicPlatform());
```
Closes #9922
Part of #9726
2016-07-08 17:47:17 +00:00
|
|
|
*
|
2018-10-19 13:37:01 +00:00
|
|
|
* @publicApi
|
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 20:07:17 +00:00
|
|
|
*/
|
2022-04-30 02:06:36 +00:00
|
|
|
@NgModule({
|
2022-11-28 12:16:29 +00:00
|
|
|
providers: [...BROWSER_MODULE_PROVIDERS, ...TESTABILITY_PROVIDERS],
|
2022-04-30 02:06:36 +00:00
|
|
|
exports: [CommonModule, ApplicationModule],
|
|
|
|
|
})
|
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 20:07:17 +00:00
|
|
|
export class BrowserModule {
|
2025-01-07 17:18:57 +00:00
|
|
|
constructor() {
|
|
|
|
|
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
|
|
|
const providersAlreadyPresent = inject(BROWSER_MODULE_PROVIDERS_MARKER, {
|
|
|
|
|
optional: true,
|
|
|
|
|
skipSelf: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (providersAlreadyPresent) {
|
|
|
|
|
throw new RuntimeError(
|
|
|
|
|
RuntimeErrorCode.BROWSER_MODULE_ALREADY_LOADED,
|
|
|
|
|
`Providers from the \`BrowserModule\` have already been loaded. If you need access ` +
|
|
|
|
|
`to common directives such as NgIf and NgFor, import the \`CommonModule\` instead.`,
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-08-18 20:34:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 20:07:17 +00:00
|
|
|
}
|