Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions devtools/projects/shell-browser/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {ChromeApplicationEnvironment} from './chrome-application-environment';
import {ChromeApplicationOperations} from './chrome-application-operations';
import {Events, MessageBus, PriorityAwareMessageBus} from '../../../protocol';
import {FrameManager} from '../../../ng-devtools/src/lib/application-services/frame_manager';
import {Platform} from '@angular/cdk/platform';
import {ChromeMessageBus} from './chrome-message-bus';

export const appConfig: ApplicationConfig = {
Expand All @@ -23,7 +22,6 @@ export const appConfig: ApplicationConfig = {
{
provide: ApplicationOperations,
useClass: ChromeApplicationOperations,
deps: [Platform],
},
{
provide: ApplicationEnvironment,
Expand Down
7 changes: 3 additions & 4 deletions goldens/public-api/router/upgrade/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
```ts

import { ComponentRef } from '@angular/core';
import { InjectionToken } from '@angular/core';
import * as i0 from '@angular/core';
import { UpgradeModule } from '@angular/upgrade/static';

// @public
export const RouterUpgradeInitializer: {
provide: InjectionToken<readonly ((compRef: ComponentRef<any>) => void)[]>;
provide: i0.InjectionToken<readonly ((compRef: ComponentRef<any>) => void)[]>;
multi: boolean;
useFactory: (ngUpgrade: UpgradeModule) => () => void;
deps: (typeof UpgradeModule)[];
useFactory: () => () => void;
};

// @public
Expand Down
5 changes: 2 additions & 3 deletions packages/common/src/i18n/localization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

import {Inject, Injectable, LOCALE_ID, ɵRuntimeError as RuntimeError} from '@angular/core';
import {inject, Inject, Injectable, LOCALE_ID, ɵRuntimeError as RuntimeError} from '@angular/core';

import {getLocalePluralCase, Plural} from './locale_data_api';
import {RuntimeErrorCode} from '../errors';
Expand All @@ -16,8 +16,7 @@ import {RuntimeErrorCode} from '../errors';
*/
@Injectable({
providedIn: 'root',
useFactory: (locale: string) => new NgLocaleLocalization(locale),
deps: [LOCALE_ID],
useFactory: () => new NgLocaleLocalization(inject(LOCALE_ID)),
})
export abstract class NgLocalization {
abstract getPluralCategory(value: any, locale?: string): string;
Expand Down
42 changes: 18 additions & 24 deletions packages/common/upgrade/src/location_upgrade_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
PathLocationStrategy,
PlatformLocation,
} from '../../index';
import {Inject, InjectionToken, ModuleWithProviders, NgModule, Optional} from '@angular/core';
import {inject, InjectionToken, ModuleWithProviders, NgModule} from '@angular/core';
import {UpgradeModule} from '@angular/upgrade/static';

import {$locationShim, $locationShimProvider} from './location_shim';
Expand Down Expand Up @@ -80,26 +80,26 @@ export class LocationUpgradeModule {
{
provide: $locationShim,
useFactory: provide$location,
deps: [UpgradeModule, Location, PlatformLocation, UrlCodec, LocationStrategy],
},
{provide: LOCATION_UPGRADE_CONFIGURATION, useValue: config ? config : {}},
{provide: UrlCodec, useFactory: provideUrlCodec, deps: [LOCATION_UPGRADE_CONFIGURATION]},
{provide: UrlCodec, useFactory: provideUrlCodec},
{
provide: APP_BASE_HREF_RESOLVED,
useFactory: provideAppBaseHref,
deps: [LOCATION_UPGRADE_CONFIGURATION, [new Inject(APP_BASE_HREF), new Optional()]],
},
{
provide: LocationStrategy,
useFactory: provideLocationStrategy,
deps: [PlatformLocation, APP_BASE_HREF_RESOLVED, LOCATION_UPGRADE_CONFIGURATION],
},
],
};
}
}

export function provideAppBaseHref(config: LocationUpgradeConfig, appBaseHref?: string) {
function provideAppBaseHref() {
const config = inject(LOCATION_UPGRADE_CONFIGURATION);
const appBaseHref = inject(APP_BASE_HREF, {optional: true});

if (config && config.appBaseHref != null) {
return config.appBaseHref;
} else if (appBaseHref != null) {
Expand All @@ -108,34 +108,28 @@ export function provideAppBaseHref(config: LocationUpgradeConfig, appBaseHref?:
return '';
}

export function provideUrlCodec(config: LocationUpgradeConfig) {
function provideUrlCodec() {
const config = inject(LOCATION_UPGRADE_CONFIGURATION);
const codec = (config && config.urlCodec) || AngularJSUrlCodec;
return new (codec as any)();
}

export function provideLocationStrategy(
platformLocation: PlatformLocation,
baseHref: string,
options: LocationUpgradeConfig = {},
) {
function provideLocationStrategy() {
const platformLocation = inject(PlatformLocation);
const baseHref = inject(APP_BASE_HREF_RESOLVED);
const options = inject(LOCATION_UPGRADE_CONFIGURATION);
return options.useHash
? new HashLocationStrategy(platformLocation, baseHref)
: new PathLocationStrategy(platformLocation, baseHref);
}

export function provide$location(
ngUpgrade: UpgradeModule,
location: Location,
platformLocation: PlatformLocation,
urlCodec: UrlCodec,
locationStrategy: LocationStrategy,
) {
function provide$location() {
const $locationProvider = new $locationShimProvider(
ngUpgrade,
location,
platformLocation,
urlCodec,
locationStrategy,
inject(UpgradeModule),
inject(Location),
inject(PlatformLocation),
inject(UrlCodec),
inject(LocationStrategy),
);

return $locationProvider.$get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

import {XhrFactory} from '@angular/common';
import {HttpBackend} from '@angular/common/http';
import {ModuleWithProviders, NgModule, Type} from '@angular/core';
import {inject, ModuleWithProviders, NgModule, Type} from '@angular/core';

import {HttpClientBackendService} from './http-client-backend-service';
import {InMemoryBackendConfig, InMemoryBackendConfigArgs, InMemoryDbService} from './interfaces';

// Internal - Creates the in-mem backend for the HttpClient module
// AoT requires factory to be exported
export function httpClientInMemBackendServiceFactory(
dbService: InMemoryDbService,
options: InMemoryBackendConfig,
xhrFactory: XhrFactory,
): HttpBackend {
return new HttpClientBackendService(dbService, options, xhrFactory) as HttpBackend;
export function httpClientInMemBackendServiceFactory(): HttpBackend {
return new HttpClientBackendService(
inject(InMemoryDbService),
inject(InMemoryBackendConfig),
inject(XhrFactory),
) as HttpBackend;
}

@NgModule()
Expand Down Expand Up @@ -55,7 +55,6 @@ export class HttpClientInMemoryWebApiModule {
{
provide: HttpBackend,
useFactory: httpClientInMemBackendServiceFactory,
deps: [InMemoryDbService, InMemoryBackendConfig, XhrFactory],
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.dev/license
*/

import {XhrFactory} from '@angular/common';
import {HttpBackend} from '@angular/common/http';
import {ModuleWithProviders, NgModule, Type} from '@angular/core';

Expand Down Expand Up @@ -45,7 +44,6 @@ export class InMemoryWebApiModule {
{
provide: HttpBackend,
useFactory: httpClientInMemBackendServiceFactory,
deps: [InMemoryDbService, InMemoryBackendConfig, XhrFactory],
},
],
};
Expand Down
11 changes: 8 additions & 3 deletions packages/platform-browser/animations/async/src/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
NgZone,
RendererFactory2,
ɵperformanceMarkFeature as performanceMarkFeature,
inject,
} from '@angular/core';
import {ɵDomRendererFactory2 as DomRendererFactory2} from '../../../index';

Expand Down Expand Up @@ -61,10 +62,14 @@ export function provideAnimationsAsync(
return makeEnvironmentProviders([
{
provide: RendererFactory2,
useFactory: (doc: Document, renderer: DomRendererFactory2, zone: NgZone) => {
return new AsyncAnimationRendererFactory(doc, renderer, zone, type);
useFactory: () => {
return new AsyncAnimationRendererFactory(
inject(DOCUMENT),
inject(DomRendererFactory2),
inject(NgZone),
type,
);
},
deps: [DOCUMENT, DomRendererFactory2, NgZone],
},
{
provide: ANIMATION_MODULE_TYPE,
Expand Down
14 changes: 6 additions & 8 deletions packages/platform-browser/animations/src/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
OnDestroy,
Provider,
RendererFactory2,
ɵChangeDetectionScheduler as ChangeDetectionScheduler,
} from '@angular/core';
import {ɵDomRendererFactory2 as DomRendererFactory2} from '../../index';

Expand All @@ -51,12 +50,12 @@ export function instantiateDefaultStyleNormalizer() {
return new WebAnimationsStyleNormalizer();
}

export function instantiateRendererFactory(
renderer: DomRendererFactory2,
engine: AnimationEngine,
zone: NgZone,
) {
return new AnimationRendererFactory(renderer, engine, zone);
export function instantiateRendererFactory() {
return new AnimationRendererFactory(
inject(DomRendererFactory2),
inject(AnimationEngine),
inject(NgZone),
);
}

const SHARED_ANIMATION_PROVIDERS: Provider[] = [
Expand All @@ -65,7 +64,6 @@ const SHARED_ANIMATION_PROVIDERS: Provider[] = [
{
provide: RendererFactory2,
useFactory: instantiateRendererFactory,
deps: [DomRendererFactory2, AnimationEngine, NgZone],
},
];

Expand Down
7 changes: 1 addition & 6 deletions packages/platform-browser/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
ErrorHandler,
InjectionToken,
NgModule,
NgZone,
PLATFORM_ID,
PLATFORM_INITIALIZER,
platformCore,
Expand All @@ -29,7 +28,6 @@ import {
RendererFactory2,
StaticProvider,
Testability,
TestabilityRegistry,
Type,
ɵINJECTOR_SCOPE as INJECTOR_SCOPE,
ɵinternalCreateApplication as internalCreateApplication,
Expand Down Expand Up @@ -239,12 +237,10 @@ const TESTABILITY_PROVIDERS = [
{
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],
},
];

Expand All @@ -255,9 +251,8 @@ const BROWSER_MODULE_PROVIDERS: Provider[] = [
provide: EVENT_MANAGER_PLUGINS,
useClass: DomEventsPlugin,
multi: true,
deps: [DOCUMENT],
},
{provide: EVENT_MANAGER_PLUGINS, useClass: KeyEventsPlugin, multi: true, deps: [DOCUMENT]},
{provide: EVENT_MANAGER_PLUGINS, useClass: KeyEventsPlugin, multi: true},
DomRendererFactory2,
SharedStylesHost,
EventManager,
Expand Down
12 changes: 5 additions & 7 deletions packages/platform-server/src/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
PlatformLocation,
ɵgetDOM as getDOM,
} from '@angular/common';
import {Inject, Injectable, Optional, ɵWritable as Writable} from '@angular/core';
import {inject, Inject, Injectable, Optional, ɵWritable as Writable} from '@angular/core';
import {Subject} from 'rxjs';

import {INITIAL_CONFIG, PlatformConfig} from './tokens';
Expand Down Expand Up @@ -57,12 +57,10 @@ export class ServerPlatformLocation implements PlatformLocation {
public readonly search: string = '';
public readonly hash: string = '';
private _hashUpdate = new Subject<LocationChangeEvent>();
private _doc = inject(DOCUMENT);

constructor(
@Inject(DOCUMENT) private _doc: any,
@Optional() @Inject(INITIAL_CONFIG) _config: any,
) {
const config = _config as PlatformConfig | null;
constructor() {
const config = inject(INITIAL_CONFIG, {optional: true});
if (!config) {
return;
}
Expand All @@ -74,7 +72,7 @@ export class ServerPlatformLocation implements PlatformLocation {
this.pathname = url.pathname;
this.search = url.search;
this.hash = url.hash;
this.href = _doc.location.href;
this.href = this._doc.location.href;
}
}

Expand Down
16 changes: 9 additions & 7 deletions packages/platform-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import {
createPlatformFactory,
Injector,
NgModule,
Optional,
PLATFORM_ID,
PLATFORM_INITIALIZER,
platformCore,
PlatformRef,
Provider,
StaticProvider,
Testability,
ɵsetDocument,
ɵTESTABILITY as TESTABILITY,
inject,
StaticProvider,
} from '@angular/core';
import {
BrowserModule,
Expand All @@ -44,18 +44,19 @@ import {INITIAL_CONFIG, PlatformConfig} from './tokens';
import {TRANSFER_STATE_SERIALIZATION_PROVIDERS} from './transfer_state';

export const INTERNAL_SERVER_PLATFORM_PROVIDERS: StaticProvider[] = [
{provide: DOCUMENT, useFactory: _document, deps: [Injector]},
{provide: DOCUMENT, useFactory: _document},
{provide: PLATFORM_ID, useValue: PLATFORM_SERVER_ID},
{provide: PLATFORM_INITIALIZER, useFactory: initDominoAdapter, multi: true, deps: [Injector]},
{provide: PLATFORM_INITIALIZER, useFactory: initDominoAdapter, multi: true},
{
provide: PlatformLocation,
useClass: ServerPlatformLocation,
deps: [DOCUMENT, [Optional, INITIAL_CONFIG]],
deps: [],
},
{provide: PlatformState, deps: [DOCUMENT]},
];

function initDominoAdapter(injector: Injector) {
function initDominoAdapter() {
const injector = inject(Injector);
const _enableDomEmulation = enableDomEmulation(injector);
return () => {
if (_enableDomEmulation) {
Expand Down Expand Up @@ -90,7 +91,8 @@ export const PLATFORM_SERVER_PROVIDERS: Provider[] = [
})
export class ServerModule {}

function _document(injector: Injector) {
function _document() {
const injector = inject(Injector);
const config: PlatformConfig | null = injector.get(INITIAL_CONFIG, null);
const _enableDomEmulation = enableDomEmulation(injector);
let document: Document;
Expand Down
6 changes: 3 additions & 3 deletions packages/router/src/provide_router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ export function provideRouter(routes: Routes, ...features: RouterFeatures[]): En
typeof ngDevMode === 'undefined' || ngDevMode
? {provide: ROUTER_IS_PROVIDED, useValue: true}
: [],
{provide: ActivatedRoute, useFactory: rootRoute, deps: [Router]},
{provide: ActivatedRoute, useFactory: rootRoute},
{provide: APP_BOOTSTRAP_LISTENER, multi: true, useFactory: getBootstrapListener},
features.map((feature) => feature.ɵproviders),
]);
}

export function rootRoute(router: Router): ActivatedRoute {
return router.routerState.root;
export function rootRoute(): ActivatedRoute {
return inject(Router).routerState.root;
}

/**
Expand Down
Loading