File tree Expand file tree Collapse file tree 4 files changed +17
-7
lines changed
goldens/public-api/core/primitives/di
packages/core/primitives/di Expand file tree Collapse file tree 4 files changed +17
-7
lines changed Original file line number Diff line number Diff line change 44
55``` ts
66
7+ // @public (undocumented)
8+ export function defineInjectable<T >(opts : {
9+ token: unknown ;
10+ providedIn? : Type <any > | ' root' | ' platform' | ' any' | ' environment' | null ;
11+ factory: () => T ;
12+ }): unknown ;
13+
714// @public (undocumented)
815export function getCurrentInjector(): Injector | undefined | null ;
916
1017// @public (undocumented)
11- export function inject<T >(token : InjectionToken <T >, options ? : unknown ): T | NotFound ;
18+ export function inject<T >(token : InjectionToken <T > | Constructor < T > , options ? : unknown ): T | NotFound ;
1219
1320// @public
1421export interface InjectionToken <T > {
Original file line number Diff line number Diff line change @@ -11,4 +11,4 @@ export type {Injector} from './src/injector';
1111export { NOT_FOUND , NotFoundError , isNotFound } from './src/not_found' ;
1212export type { NotFound } from './src/not_found' ;
1313export type { InjectionToken , ɵɵInjectableDeclaration } from './src/injection_token' ;
14- export { registerInjectable } from './src/injection_token' ;
14+ export { defineInjectable , registerInjectable } from './src/injection_token' ;
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ export function defineInjectable<T>(opts: {
8080 } as ɵɵInjectableDeclaration < T > ;
8181}
8282
83- type Constructor < T > = Function & { prototype : T } ;
83+ export type Constructor < T > = Function & { prototype : T } ;
8484
8585export function registerInjectable < T > (
8686 ctor : unknown ,
Original file line number Diff line number Diff line change 66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { InjectionToken } from './injection_token' ;
9+ import { Constructor , InjectionToken } from './injection_token' ;
1010import { NotFound , NOT_FOUND } from './not_found' ;
1111
1212export interface Injector {
@@ -33,10 +33,13 @@ export function setCurrentInjector(
3333 return former ;
3434}
3535
36- export function inject < T > ( token : InjectionToken < T > , options ?: unknown ) : T | NotFound {
36+ export function inject < T > (
37+ token : InjectionToken < T > | Constructor < T > ,
38+ options ?: unknown ,
39+ ) : T | NotFound {
3740 const currentInjector = getCurrentInjector ( ) ;
38- if ( ! currentInjector ) {
41+ if ( ! currentInjector || ! ( token as InjectionToken < T > ) . ɵprov ) {
3942 return NOT_FOUND ;
4043 }
41- return currentInjector . retrieve ( token , options ) ;
44+ return currentInjector . retrieve ( token as InjectionToken < T > , options ) ;
4245}
You can’t perform that action at this time.
0 commit comments