refactor(core): add single type for injector token (#41580)
Currently we have a lot of places where we repeat the type `Type<T>|AbstractType<T>|InjectionToken<T>` which makes it cumbersome to add another type or to type something else with the same signature. These changes add a new type that can be used instead. Fixes #39792. PR Close #41580
This commit is contained in:
parent
3ceb3dea67
commit
de4fafb818
|
@ -159,11 +159,11 @@ export declare interface ConstructorSansProvider {
|
|||
export declare type ContentChild = Query;
|
||||
|
||||
export declare interface ContentChildDecorator {
|
||||
(selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: {
|
||||
(selector: ProviderToken<unknown> | Function | string, opts?: {
|
||||
read?: any;
|
||||
static?: boolean;
|
||||
}): any;
|
||||
new (selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: {
|
||||
new (selector: ProviderToken<unknown> | Function | string, opts?: {
|
||||
read?: any;
|
||||
static?: boolean;
|
||||
}): ContentChild;
|
||||
|
@ -172,12 +172,12 @@ export declare interface ContentChildDecorator {
|
|||
export declare type ContentChildren = Query;
|
||||
|
||||
export declare interface ContentChildrenDecorator {
|
||||
(selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: {
|
||||
(selector: ProviderToken<unknown> | Function | string, opts?: {
|
||||
descendants?: boolean;
|
||||
emitDistinctChangesOnly?: boolean;
|
||||
read?: any;
|
||||
}): any;
|
||||
new (selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: {
|
||||
new (selector: ProviderToken<unknown> | Function | string, opts?: {
|
||||
descendants?: boolean;
|
||||
emitDistinctChangesOnly?: boolean;
|
||||
read?: any;
|
||||
|
@ -448,7 +448,7 @@ export declare class InjectionToken<T> {
|
|||
}
|
||||
|
||||
export declare abstract class Injector {
|
||||
abstract get<T>(token: Type<T> | AbstractType<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
abstract get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
/** @deprecated */ abstract get(token: any, notFoundValue?: any): any;
|
||||
static NULL: Injector;
|
||||
static THROW_IF_NOT_FOUND: {};
|
||||
|
@ -680,8 +680,8 @@ export declare function ɵɵdefineInjectable<T>(opts: {
|
|||
}): unknown;
|
||||
|
||||
/** @codeGenApi */
|
||||
export declare function ɵɵinject<T>(token: Type<T> | AbstractType<T> | InjectionToken<T>): T;
|
||||
export declare function ɵɵinject<T>(token: Type<T> | AbstractType<T> | InjectionToken<T>, flags?: InjectFlags): T | null;
|
||||
export declare function ɵɵinject<T>(token: ProviderToken<T>): T;
|
||||
export declare function ɵɵinject<T>(token: ProviderToken<T>, flags?: InjectFlags): T | null;
|
||||
|
||||
/** @codeGenApi */
|
||||
export declare function ɵɵinjectAttribute(attrNameToInject: string): string | null;
|
||||
|
@ -725,6 +725,8 @@ export declare interface Predicate<T> {
|
|||
|
||||
export declare type Provider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider | ExistingProvider | FactoryProvider | any[];
|
||||
|
||||
export declare type ProviderToken<T> = Type<T> | AbstractType<T> | InjectionToken<T>;
|
||||
|
||||
export declare interface Query {
|
||||
descendants: boolean;
|
||||
emitDistinctChangesOnly: boolean;
|
||||
|
@ -989,11 +991,11 @@ export declare const VERSION: Version;
|
|||
export declare type ViewChild = Query;
|
||||
|
||||
export declare interface ViewChildDecorator {
|
||||
(selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: {
|
||||
(selector: ProviderToken<unknown> | Function | string, opts?: {
|
||||
read?: any;
|
||||
static?: boolean;
|
||||
}): any;
|
||||
new (selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: {
|
||||
new (selector: ProviderToken<unknown> | Function | string, opts?: {
|
||||
read?: any;
|
||||
static?: boolean;
|
||||
}): ViewChild;
|
||||
|
@ -1002,11 +1004,11 @@ export declare interface ViewChildDecorator {
|
|||
export declare type ViewChildren = Query;
|
||||
|
||||
export declare interface ViewChildrenDecorator {
|
||||
(selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: {
|
||||
(selector: ProviderToken<unknown> | Function | string, opts?: {
|
||||
read?: any;
|
||||
emitDistinctChangesOnly?: boolean;
|
||||
}): any;
|
||||
new (selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: {
|
||||
new (selector: ProviderToken<unknown> | Function | string, opts?: {
|
||||
read?: any;
|
||||
emitDistinctChangesOnly?: boolean;
|
||||
}): ViewChildren;
|
||||
|
|
|
@ -62,11 +62,11 @@ export declare interface TestBed {
|
|||
configureTestingModule(moduleDef: TestModuleMetadata): void;
|
||||
createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
||||
execute(tokens: any[], fn: Function, context?: any): any;
|
||||
/** @deprecated */ get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
/** @deprecated */ get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
/** @deprecated */ get(token: any, notFoundValue?: any): any;
|
||||
initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): void;
|
||||
inject<T>(token: Type<T> | InjectionToken<T> | AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
inject<T>(token: Type<T> | InjectionToken<T> | AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T | null;
|
||||
inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T | null;
|
||||
overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void;
|
||||
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void;
|
||||
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void;
|
||||
|
@ -99,11 +99,11 @@ export declare interface TestBedStatic {
|
|||
}): TestBedStatic;
|
||||
configureTestingModule(moduleDef: TestModuleMetadata): TestBedStatic;
|
||||
createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
||||
/** @deprecated */ get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
/** @deprecated */ get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
/** @deprecated */ get(token: any, notFoundValue?: any): any;
|
||||
initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed;
|
||||
inject<T>(token: Type<T> | InjectionToken<T> | AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
inject<T>(token: Type<T> | InjectionToken<T> | AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T | null;
|
||||
inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T | null;
|
||||
overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBedStatic;
|
||||
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBedStatic;
|
||||
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic;
|
||||
|
|
|
@ -18,6 +18,7 @@ export {ɵɵdefineInjectable, defineInjectable, ɵɵdefineInjector, InjectableTy
|
|||
export {forwardRef, resolveForwardRef, ForwardRefFn} from './forward_ref';
|
||||
export {Injectable, InjectableDecorator, InjectableProvider} from './injectable';
|
||||
export {Injector} from './injector';
|
||||
export {ProviderToken} from './provider_token';
|
||||
export {ɵɵinject, inject, ɵɵinvalidFactoryDep} from './injector_compatibility';
|
||||
export {INJECTOR} from './injector_token';
|
||||
export {ReflectiveInjector} from './reflective_injector';
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AbstractType, Type} from '../interface/type';
|
||||
import {throwProviderNotFoundError} from '../render3/errors_di';
|
||||
import {assertNotEqual} from '../util/assert';
|
||||
import {stringify} from '../util/stringify';
|
||||
import {InjectionToken} from './injection_token';
|
||||
|
||||
import {getInjectableDef, ɵɵInjectableDeclaration} from './interface/defs';
|
||||
import {InjectFlags} from './interface/injector';
|
||||
import {ProviderToken} from './provider_token';
|
||||
|
||||
|
||||
/**
|
||||
|
@ -24,8 +24,7 @@ import {InjectFlags} from './interface/injector';
|
|||
* 1. `Injector` should not depend on ivy logic.
|
||||
* 2. To maintain tree shake-ability we don't want to bring in unnecessary code.
|
||||
*/
|
||||
let _injectImplementation:
|
||||
(<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags) => T | null)|
|
||||
let _injectImplementation: (<T>(token: ProviderToken<T>, flags?: InjectFlags) => T | null)|
|
||||
undefined;
|
||||
export function getInjectImplementation() {
|
||||
return _injectImplementation;
|
||||
|
@ -36,10 +35,8 @@ export function getInjectImplementation() {
|
|||
* Sets the current inject implementation.
|
||||
*/
|
||||
export function setInjectImplementation(
|
||||
impl: (<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags) => T | null)|
|
||||
undefined):
|
||||
(<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags) => T | null)|
|
||||
undefined {
|
||||
impl: (<T>(token: ProviderToken<T>, flags?: InjectFlags) => T | null)|
|
||||
undefined): (<T>(token: ProviderToken<T>, flags?: InjectFlags) => T | null)|undefined {
|
||||
const previous = _injectImplementation;
|
||||
_injectImplementation = impl;
|
||||
return previous;
|
||||
|
@ -54,8 +51,7 @@ export function setInjectImplementation(
|
|||
* injectable definition.
|
||||
*/
|
||||
export function injectRootLimpMode<T>(
|
||||
token: Type<T>|AbstractType<T>|InjectionToken<T>, notFoundValue: T|undefined,
|
||||
flags: InjectFlags): T|null {
|
||||
token: ProviderToken<T>, notFoundValue: T|undefined, flags: InjectFlags): T|null {
|
||||
const injectableDef: ɵɵInjectableDeclaration<T>|null = getInjectableDef(token);
|
||||
if (injectableDef && injectableDef.providedIn == 'root') {
|
||||
return injectableDef.value === undefined ? injectableDef.value = injectableDef.factory() :
|
||||
|
@ -75,7 +71,7 @@ export function injectRootLimpMode<T>(
|
|||
* @param fn Function which it should not equal to
|
||||
*/
|
||||
export function assertInjectImplementationNotEqual(
|
||||
fn: (<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags) => T | null)) {
|
||||
fn: (<T>(token: ProviderToken<T>, flags?: InjectFlags) => T | null)) {
|
||||
ngDevMode &&
|
||||
assertNotEqual(_injectImplementation, fn, 'Calling ɵɵinject would cause infinite recursion');
|
||||
}
|
||||
|
|
|
@ -6,10 +6,9 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AbstractType, Type} from '../interface/type';
|
||||
import {stringify} from '../util/stringify';
|
||||
|
||||
import {resolveForwardRef} from './forward_ref';
|
||||
import {InjectionToken} from './injection_token';
|
||||
import {catchInjectorError, formatError, NG_TEMP_TOKEN_PATH, setCurrentInjector, THROW_IF_NOT_FOUND, USE_VALUE, ɵɵinject} from './injector_compatibility';
|
||||
import {InjectorMarkers} from './injector_marker';
|
||||
import {INJECTOR} from './injector_token';
|
||||
|
@ -18,6 +17,7 @@ import {InjectFlags} from './interface/injector';
|
|||
import {ConstructorProvider, ExistingProvider, FactoryProvider, StaticClassProvider, StaticProvider, ValueProvider} from './interface/provider';
|
||||
import {Inject, Optional, Self, SkipSelf} from './metadata';
|
||||
import {NullInjector} from './null_injector';
|
||||
import {ProviderToken} from './provider_token';
|
||||
import {createInjector} from './r3_injector';
|
||||
import {INJECTOR_SCOPE} from './scope';
|
||||
|
||||
|
@ -66,10 +66,9 @@ export abstract class Injector {
|
|||
* @returns The instance from the injector if defined, otherwise the `notFoundValue`.
|
||||
* @throws When the `notFoundValue` is `undefined` or `Injector.THROW_IF_NOT_FOUND`.
|
||||
*/
|
||||
abstract get<T>(
|
||||
token: Type<T>|AbstractType<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
abstract get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
/**
|
||||
* @deprecated from v4.0.0 use Type<T>, AbstractType<T> or InjectionToken<T>
|
||||
* @deprecated from v4.0.0 use ProviderToken<T>
|
||||
* @suppress {duplicate}
|
||||
*/
|
||||
abstract get(token: any, notFoundValue?: any): any;
|
||||
|
@ -156,8 +155,7 @@ export class StaticInjector implements Injector {
|
|||
this.scope = recursivelyProcessProviders(records, providers);
|
||||
}
|
||||
|
||||
get<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags):
|
||||
T;
|
||||
get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
get(token: any, notFoundValue?: any): any;
|
||||
get(token: any, notFoundValue?: any, flags: InjectFlags = InjectFlags.Default): any {
|
||||
const records = this._records;
|
||||
|
|
|
@ -8,16 +8,16 @@
|
|||
|
||||
import '../util/ng_dev_mode';
|
||||
|
||||
import {AbstractType, Type} from '../interface/type';
|
||||
import {Type} from '../interface/type';
|
||||
import {getClosureSafeProperty} from '../util/property';
|
||||
import {stringify} from '../util/stringify';
|
||||
|
||||
import {resolveForwardRef} from './forward_ref';
|
||||
import {getInjectImplementation, injectRootLimpMode} from './inject_switch';
|
||||
import {InjectionToken} from './injection_token';
|
||||
import {Injector} from './injector';
|
||||
import {DecoratorFlags, InjectFlags, InternalInjectFlags} from './interface/injector';
|
||||
import {ValueProvider} from './interface/provider';
|
||||
import {ProviderToken} from './provider_token';
|
||||
|
||||
|
||||
const _THROW_IF_NOT_FOUND = {};
|
||||
|
@ -53,11 +53,10 @@ export function setCurrentInjector(injector: Injector|null|undefined): Injector|
|
|||
return former;
|
||||
}
|
||||
|
||||
export function injectInjectorOnly<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>): T;
|
||||
export function injectInjectorOnly<T>(
|
||||
token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags): T|null;
|
||||
export function injectInjectorOnly<T>(
|
||||
token: Type<T>|AbstractType<T>|InjectionToken<T>, flags = InjectFlags.Default): T|null {
|
||||
export function injectInjectorOnly<T>(token: ProviderToken<T>): T;
|
||||
export function injectInjectorOnly<T>(token: ProviderToken<T>, flags?: InjectFlags): T|null;
|
||||
export function injectInjectorOnly<T>(token: ProviderToken<T>, flags = InjectFlags.Default): T|
|
||||
null {
|
||||
if (_currentInjector === undefined) {
|
||||
throw new Error(`inject() must be called from an injection context`);
|
||||
} else if (_currentInjector === null) {
|
||||
|
@ -80,11 +79,9 @@ export function injectInjectorOnly<T>(
|
|||
* @codeGenApi
|
||||
* @publicApi This instruction has been emitted by ViewEngine for some time and is deployed to npm.
|
||||
*/
|
||||
export function ɵɵinject<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>): T;
|
||||
export function ɵɵinject<T>(
|
||||
token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags): T|null;
|
||||
export function ɵɵinject<T>(
|
||||
token: Type<T>|AbstractType<T>|InjectionToken<T>, flags = InjectFlags.Default): T|null {
|
||||
export function ɵɵinject<T>(token: ProviderToken<T>): T;
|
||||
export function ɵɵinject<T>(token: ProviderToken<T>, flags?: InjectFlags): T|null;
|
||||
export function ɵɵinject<T>(token: ProviderToken<T>, flags = InjectFlags.Default): T|null {
|
||||
return (getInjectImplementation() || injectInjectorOnly)(resolveForwardRef(token), flags);
|
||||
}
|
||||
|
||||
|
@ -138,7 +135,7 @@ Please check that 1) the type for the parameter at index ${
|
|||
*/
|
||||
export const inject = ɵɵinject;
|
||||
|
||||
export function injectArgs(types: (Type<any>|InjectionToken<any>|any[])[]): any[] {
|
||||
export function injectArgs(types: (ProviderToken<any>|any[])[]): any[] {
|
||||
const args: any[] = [];
|
||||
for (let i = 0; i < types.length; i++) {
|
||||
const arg = resolveForwardRef(types[i]);
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AbstractType, Type} from '../interface/type';
|
||||
import {InjectionToken} from './injection_token';
|
||||
|
||||
/**
|
||||
* @description
|
||||
*
|
||||
* Token that can be used to retrieve an instance from an injector or through a query.
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export type ProviderToken<T> = Type<T>|AbstractType<T>|InjectionToken<T>;
|
|
@ -9,7 +9,7 @@
|
|||
import '../util/ng_dev_mode';
|
||||
|
||||
import {OnDestroy} from '../interface/lifecycle_hooks';
|
||||
import {AbstractType, Type} from '../interface/type';
|
||||
import {Type} from '../interface/type';
|
||||
import {FactoryFn, getFactoryDef} from '../render3/definition_factory';
|
||||
import {throwCyclicDependencyError, throwInvalidProviderError, throwMixedMultiProviderError} from '../render3/errors_di';
|
||||
import {deepForEach, newArray} from '../util/array_utils';
|
||||
|
@ -25,6 +25,7 @@ import {getInheritedInjectableDef, getInjectableDef, getInjectorDef, InjectorTyp
|
|||
import {InjectFlags} from './interface/injector';
|
||||
import {ClassProvider, ConstructorProvider, ExistingProvider, FactoryProvider, StaticClassProvider, StaticProvider, TypeProvider, ValueProvider} from './interface/provider';
|
||||
import {NullInjector} from './null_injector';
|
||||
import {ProviderToken} from './provider_token';
|
||||
import {INJECTOR_SCOPE} from './scope';
|
||||
|
||||
|
||||
|
@ -102,7 +103,7 @@ export class R3Injector {
|
|||
* - `null` value implies that we don't have the record. Used by tree-shakable injectors
|
||||
* to prevent further searches.
|
||||
*/
|
||||
private records = new Map<Type<any>|AbstractType<any>|InjectionToken<any>, Record<any>|null>();
|
||||
private records = new Map<ProviderToken<any>, Record<any>|null>();
|
||||
|
||||
/**
|
||||
* The transitive set of `InjectorType`s which define this injector.
|
||||
|
@ -180,7 +181,7 @@ export class R3Injector {
|
|||
}
|
||||
|
||||
get<T>(
|
||||
token: Type<T>|AbstractType<T>|InjectionToken<T>, notFoundValue: any = THROW_IF_NOT_FOUND,
|
||||
token: ProviderToken<T>, notFoundValue: any = THROW_IF_NOT_FOUND,
|
||||
flags = InjectFlags.Default): T {
|
||||
this.assertNotDestroyed();
|
||||
// Set the injection context.
|
||||
|
@ -404,7 +405,7 @@ export class R3Injector {
|
|||
this.records.set(token, record);
|
||||
}
|
||||
|
||||
private hydrate<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, record: Record<T>): T {
|
||||
private hydrate<T>(token: ProviderToken<T>, record: Record<T>): T {
|
||||
if (ngDevMode && record.value === CIRCULAR) {
|
||||
throwCyclicDependencyError(stringify(token));
|
||||
} else if (record.value === NOT_YET) {
|
||||
|
@ -430,8 +431,7 @@ export class R3Injector {
|
|||
}
|
||||
}
|
||||
|
||||
function injectableDefOrInjectorDefFactory(token: Type<any>|AbstractType<any>|
|
||||
InjectionToken<any>): FactoryFn<any> {
|
||||
function injectableDefOrInjectorDefFactory(token: ProviderToken<any>): FactoryFn<any> {
|
||||
// Most tokens will have an injectable def directly on them, which specifies a factory directly.
|
||||
const injectableDef = getInjectableDef(token);
|
||||
const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token);
|
||||
|
@ -560,8 +560,7 @@ function hasOnDestroy(value: any): value is OnDestroy {
|
|||
typeof (value as OnDestroy).ngOnDestroy === 'function';
|
||||
}
|
||||
|
||||
function couldBeInjectableType(value: any): value is Type<any>|AbstractType<any>|
|
||||
InjectionToken<any> {
|
||||
function couldBeInjectableType(value: any): value is ProviderToken<any> {
|
||||
return (typeof value === 'function') ||
|
||||
(typeof value === 'object' && value instanceof InjectionToken);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
import {InjectionToken} from '../di/injection_token';
|
||||
import {Type} from '../interface/type';
|
||||
import {ProviderToken} from '../di/provider_token';
|
||||
import {makePropDecorator} from '../util/decorators';
|
||||
|
||||
/**
|
||||
|
@ -169,12 +169,12 @@ export interface ContentChildrenDecorator {
|
|||
*
|
||||
* @Annotation
|
||||
*/
|
||||
(selector: Type<any>|InjectionToken<unknown>|Function|string, opts?: {
|
||||
(selector: ProviderToken<unknown>|Function|string, opts?: {
|
||||
descendants?: boolean,
|
||||
emitDistinctChangesOnly?: boolean,
|
||||
read?: any,
|
||||
}): any;
|
||||
new(selector: Type<any>|InjectionToken<unknown>|Function|string,
|
||||
new(selector: ProviderToken<unknown>|Function|string,
|
||||
opts?: {descendants?: boolean, emitDistinctChangesOnly?: boolean, read?: any}): Query;
|
||||
}
|
||||
|
||||
|
@ -240,9 +240,8 @@ export interface ContentChildDecorator {
|
|||
*
|
||||
* @Annotation
|
||||
*/
|
||||
(selector: Type<any>|InjectionToken<unknown>|Function|string,
|
||||
opts?: {read?: any, static?: boolean}): any;
|
||||
new(selector: Type<any>|InjectionToken<unknown>|Function|string,
|
||||
(selector: ProviderToken<unknown>|Function|string, opts?: {read?: any, static?: boolean}): any;
|
||||
new(selector: ProviderToken<unknown>|Function|string,
|
||||
opts?: {read?: any, static?: boolean}): ContentChild;
|
||||
}
|
||||
|
||||
|
@ -304,9 +303,9 @@ export interface ViewChildrenDecorator {
|
|||
*
|
||||
* @Annotation
|
||||
*/
|
||||
(selector: Type<any>|InjectionToken<unknown>|Function|string,
|
||||
(selector: ProviderToken<unknown>|Function|string,
|
||||
opts?: {read?: any, emitDistinctChangesOnly?: boolean}): any;
|
||||
new(selector: Type<any>|InjectionToken<unknown>|Function|string,
|
||||
new(selector: ProviderToken<unknown>|Function|string,
|
||||
opts?: {read?: any, emitDistinctChangesOnly?: boolean}): ViewChildren;
|
||||
}
|
||||
|
||||
|
@ -379,9 +378,8 @@ export interface ViewChildDecorator {
|
|||
*
|
||||
* @Annotation
|
||||
*/
|
||||
(selector: Type<any>|InjectionToken<unknown>|Function|string,
|
||||
opts?: {read?: any, static?: boolean}): any;
|
||||
new(selector: Type<any>|InjectionToken<unknown>|Function|string,
|
||||
(selector: ProviderToken<unknown>|Function|string, opts?: {read?: any, static?: boolean}): any;
|
||||
new(selector: ProviderToken<unknown>|Function|string,
|
||||
opts?: {read?: any, static?: boolean}): ViewChild;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ import {ChangeDetectorRef as ViewEngine_ChangeDetectorRef} from '../change_detec
|
|||
import {InjectionToken} from '../di/injection_token';
|
||||
import {Injector} from '../di/injector';
|
||||
import {InjectFlags} from '../di/interface/injector';
|
||||
import {AbstractType, Type} from '../interface/type';
|
||||
import {ProviderToken} from '../di/provider_token';
|
||||
import {Type} from '../interface/type';
|
||||
import {ComponentFactory as viewEngine_ComponentFactory, ComponentRef as viewEngine_ComponentRef} from '../linker/component_factory';
|
||||
import {ComponentFactoryResolver as viewEngine_ComponentFactoryResolver} from '../linker/component_factory_resolver';
|
||||
import {createElementRef, ElementRef as viewEngine_ElementRef} from '../linker/element_ref';
|
||||
|
@ -80,9 +81,7 @@ export const SCHEDULER = new InjectionToken<((fn: () => void) => void)>('SCHEDUL
|
|||
|
||||
function createChainedInjector(rootViewInjector: Injector, moduleInjector: Injector): Injector {
|
||||
return {
|
||||
get: <T>(
|
||||
token: Type<T>|AbstractType<T>|InjectionToken<T>, notFoundValue?: T,
|
||||
flags?: InjectFlags): T => {
|
||||
get: <T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T => {
|
||||
const value = rootViewInjector.get(token, NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as T, flags);
|
||||
|
||||
if (value !== NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR ||
|
||||
|
|
|
@ -8,12 +8,11 @@
|
|||
|
||||
import {isForwardRef, resolveForwardRef} from '../di/forward_ref';
|
||||
import {injectRootLimpMode, setInjectImplementation} from '../di/inject_switch';
|
||||
import {InjectionToken} from '../di/injection_token';
|
||||
import {Injector} from '../di/injector';
|
||||
import {InjectorMarkers} from '../di/injector_marker';
|
||||
import {getInjectableDef} from '../di/interface/defs';
|
||||
import {InjectFlags} from '../di/interface/injector';
|
||||
import {AbstractType, Type} from '../interface/type';
|
||||
import {ProviderToken} from '../di/provider_token';
|
||||
import {Type} from '../interface/type';
|
||||
import {assertDefined, assertEqual, assertIndexInRange} from '../util/assert';
|
||||
import {noSideEffects} from '../util/closure';
|
||||
|
||||
|
@ -106,7 +105,7 @@ let nextNgElementId = 0;
|
|||
* @param type The directive token to register
|
||||
*/
|
||||
export function bloomAdd(
|
||||
injectorIndex: number, tView: TView, type: Type<any>|InjectionToken<any>|string): void {
|
||||
injectorIndex: number, tView: TView, type: ProviderToken<any>|string): void {
|
||||
ngDevMode && assertEqual(tView.firstCreatePass, true, 'expected firstCreatePass to be true');
|
||||
let id: number|undefined;
|
||||
if (typeof type === 'string') {
|
||||
|
@ -264,7 +263,7 @@ export function getParentInjectorLocation(tNode: TNode, lView: LView): RelativeI
|
|||
* @param token The type or the injection token to be made public
|
||||
*/
|
||||
export function diPublicInInjector(
|
||||
injectorIndex: number, tView: TView, token: InjectionToken<any>|Type<any>): void {
|
||||
injectorIndex: number, tView: TView, token: ProviderToken<any>): void {
|
||||
bloomAdd(injectorIndex, tView, token);
|
||||
}
|
||||
|
||||
|
@ -344,8 +343,7 @@ export function injectAttributeImpl(tNode: TNode, attrNameToInject: string): str
|
|||
|
||||
|
||||
function notFoundValueOrThrow<T>(
|
||||
notFoundValue: T|null, token: Type<T>|AbstractType<T>|InjectionToken<T>, flags: InjectFlags): T|
|
||||
null {
|
||||
notFoundValue: T|null, token: ProviderToken<T>, flags: InjectFlags): T|null {
|
||||
if (flags & InjectFlags.Optional) {
|
||||
return notFoundValue;
|
||||
} else {
|
||||
|
@ -363,8 +361,7 @@ function notFoundValueOrThrow<T>(
|
|||
* @returns the value from the injector or throws an exception
|
||||
*/
|
||||
function lookupTokenUsingModuleInjector<T>(
|
||||
lView: LView, token: Type<T>|AbstractType<T>|InjectionToken<T>, flags: InjectFlags,
|
||||
notFoundValue?: any): T|null {
|
||||
lView: LView, token: ProviderToken<T>, flags: InjectFlags, notFoundValue?: any): T|null {
|
||||
if (flags & InjectFlags.Optional && notFoundValue === undefined) {
|
||||
// This must be set or the NullInjector will throw for optional deps
|
||||
notFoundValue = null;
|
||||
|
@ -406,7 +403,7 @@ function lookupTokenUsingModuleInjector<T>(
|
|||
* @returns the value from the injector, `null` when not found, or `notFoundValue` if provided
|
||||
*/
|
||||
export function getOrCreateInjectable<T>(
|
||||
tNode: TDirectiveHostNode|null, lView: LView, token: Type<T>|AbstractType<T>|InjectionToken<T>,
|
||||
tNode: TDirectiveHostNode|null, lView: LView, token: ProviderToken<T>,
|
||||
flags: InjectFlags = InjectFlags.Default, notFoundValue?: any): T|null {
|
||||
if (tNode !== null) {
|
||||
const bloomHash = bloomHashBitOrFactory(token);
|
||||
|
@ -506,8 +503,8 @@ export function createNodeInjector(): Injector {
|
|||
}
|
||||
|
||||
function searchTokensOnInjector<T>(
|
||||
injectorIndex: number, lView: LView, token: Type<T>|AbstractType<T>|InjectionToken<T>,
|
||||
previousTView: TView|null, flags: InjectFlags, hostTElementNode: TNode|null) {
|
||||
injectorIndex: number, lView: LView, token: ProviderToken<T>, previousTView: TView|null,
|
||||
flags: InjectFlags, hostTElementNode: TNode|null) {
|
||||
const currentTView = lView[TVIEW];
|
||||
const tNode = currentTView.data[injectorIndex + NodeInjectorOffset.TNODE] as TNode;
|
||||
// First, we need to determine if view providers can be accessed by the starting element.
|
||||
|
@ -553,8 +550,8 @@ function searchTokensOnInjector<T>(
|
|||
* @returns Index of a found directive or provider, or null when none found.
|
||||
*/
|
||||
export function locateDirectiveOrProvider<T>(
|
||||
tNode: TNode, tView: TView, token: Type<T>|AbstractType<T>|InjectionToken<T>|string,
|
||||
canAccessViewProviders: boolean, isHostSpecialCase: boolean|number): number|null {
|
||||
tNode: TNode, tView: TView, token: ProviderToken<T>|string, canAccessViewProviders: boolean,
|
||||
isHostSpecialCase: boolean|number): number|null {
|
||||
const nodeProviderIndexes = tNode.providerIndexes;
|
||||
const tInjectables = tView.data;
|
||||
|
||||
|
@ -568,8 +565,7 @@ export function locateDirectiveOrProvider<T>(
|
|||
// When the host special case applies, only the viewProviders and the component are visible
|
||||
const endIndex = isHostSpecialCase ? injectablesStart + cptViewProvidersCount : directiveEnd;
|
||||
for (let i = startingIndex; i < endIndex; i++) {
|
||||
const providerTokenOrDef =
|
||||
tInjectables[i] as InjectionToken<any>| Type<any>| DirectiveDef<any>| string;
|
||||
const providerTokenOrDef = tInjectables[i] as ProviderToken<any>| DirectiveDef<any>| string;
|
||||
if (i < directivesStart && token === providerTokenOrDef ||
|
||||
i >= directivesStart && (providerTokenOrDef as DirectiveDef<any>).type === token) {
|
||||
return i;
|
||||
|
@ -644,8 +640,7 @@ export function getNodeInjectable(
|
|||
* @returns the matching bit to check in the bloom filter or `null` if the token is not known.
|
||||
* When the returned value is negative then it represents special values such as `Injector`.
|
||||
*/
|
||||
export function bloomHashBitOrFactory(token: Type<any>|AbstractType<any>|InjectionToken<any>|
|
||||
string): number|Function|undefined {
|
||||
export function bloomHashBitOrFactory(token: ProviderToken<any>|string): number|Function|undefined {
|
||||
ngDevMode && assertDefined(token, 'token must be defined');
|
||||
if (typeof token === 'string') {
|
||||
return token.charCodeAt(0) || 0;
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {InjectFlags, InjectionToken, resolveForwardRef} from '../../di';
|
||||
import {InjectFlags, resolveForwardRef} from '../../di';
|
||||
import {assertInjectImplementationNotEqual} from '../../di/inject_switch';
|
||||
import {ɵɵinject} from '../../di/injector_compatibility';
|
||||
import {AbstractType, Type} from '../../interface/type';
|
||||
import {ProviderToken} from '../../di/provider_token';
|
||||
import {getOrCreateInjectable} from '../di';
|
||||
import {TDirectiveHostNode} from '../interfaces/node';
|
||||
import {getCurrentTNode, getLView} from '../state';
|
||||
|
@ -37,11 +37,9 @@ import {getCurrentTNode, getLView} from '../state';
|
|||
*
|
||||
* @codeGenApi
|
||||
*/
|
||||
export function ɵɵdirectiveInject<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>): T;
|
||||
export function ɵɵdirectiveInject<T>(
|
||||
token: Type<T>|AbstractType<T>|InjectionToken<T>, flags: InjectFlags): T;
|
||||
export function ɵɵdirectiveInject<T>(
|
||||
token: Type<T>|AbstractType<T>|InjectionToken<T>, flags = InjectFlags.Default): T|null {
|
||||
export function ɵɵdirectiveInject<T>(token: ProviderToken<T>): T;
|
||||
export function ɵɵdirectiveInject<T>(token: ProviderToken<T>, flags: InjectFlags): T;
|
||||
export function ɵɵdirectiveInject<T>(token: ProviderToken<T>, flags = InjectFlags.Default): T|null {
|
||||
const lView = getLView();
|
||||
// Fall back to inject() if view hasn't been created. This situation can happen in tests
|
||||
// if inject utilities are used before bootstrapping.
|
||||
|
|
|
@ -6,9 +6,8 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {InjectionToken} from '../../di/injection_token';
|
||||
import {InjectFlags} from '../../di/interface/injector';
|
||||
import {AbstractType, Type} from '../../interface/type';
|
||||
import {ProviderToken} from '../../di/provider_token';
|
||||
import {assertDefined, assertEqual} from '../../util/assert';
|
||||
|
||||
import {TDirectiveHostNode} from './node';
|
||||
|
@ -176,8 +175,7 @@ export class NodeInjectorFactory {
|
|||
/**
|
||||
* The inject implementation to be activated when using the factory.
|
||||
*/
|
||||
injectImpl: null|
|
||||
(<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags) => T);
|
||||
injectImpl: null|(<T>(token: ProviderToken<T>, flags?: InjectFlags) => T);
|
||||
|
||||
/**
|
||||
* Marker set to true during factory invocation to see if we get into recursive loop.
|
||||
|
@ -280,8 +278,7 @@ export class NodeInjectorFactory {
|
|||
* Set to `true` if the token is declared in `viewProviders` (or if it is component).
|
||||
*/
|
||||
isViewProvider: boolean,
|
||||
injectImplementation: null|
|
||||
(<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags) => T)) {
|
||||
injectImplementation: null|(<T>(token: ProviderToken<T>, flags?: InjectFlags) => T)) {
|
||||
ngDevMode && assertDefined(factory, 'Factory not specified');
|
||||
ngDevMode && assertEqual(typeof factory, 'function', 'Expected factory function.');
|
||||
this.canSeeViewProviders = isViewProvider;
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {InjectionToken} from '../../di/injection_token';
|
||||
import {Type} from '../../interface/type';
|
||||
import {ProviderToken} from '../../di/provider_token';
|
||||
import {QueryList} from '../../linker/query_list';
|
||||
|
||||
import {TNode} from './node';
|
||||
|
@ -17,7 +16,7 @@ import {TView} from './view';
|
|||
* An object representing query metadata extracted from query annotations.
|
||||
*/
|
||||
export interface TQueryMetadata {
|
||||
predicate: Type<any>|InjectionToken<unknown>|string[];
|
||||
predicate: ProviderToken<unknown>|string[];
|
||||
read: any;
|
||||
flags: QueryFlags;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {InjectionToken} from '../../di/injection_token';
|
||||
import {Injector} from '../../di/injector';
|
||||
import {ProviderToken} from '../../di/provider_token';
|
||||
import {Type} from '../../interface/type';
|
||||
import {SchemaMetadata} from '../../metadata/schema';
|
||||
import {Sanitizer} from '../../sanitization/sanitizer';
|
||||
|
@ -904,9 +904,8 @@ export type DestroyHookData = (HookEntry|HookData)[];
|
|||
*
|
||||
* Injector bloom filters are also stored here.
|
||||
*/
|
||||
export type TData =
|
||||
(TNode|PipeDef<any>|DirectiveDef<any>|ComponentDef<any>|number|TStylingRange|TStylingKey|
|
||||
Type<any>|InjectionToken<any>|TI18n|I18nUpdateOpCodes|TIcu|null|string)[];
|
||||
export type TData = (TNode|PipeDef<any>|DirectiveDef<any>|ComponentDef<any>|number|TStylingRange|
|
||||
TStylingKey|ProviderToken<any>|TI18n|I18nUpdateOpCodes|TIcu|null|string)[];
|
||||
|
||||
// Note: This hack is necessary so we don't erroneously get a circular dependency
|
||||
// failure based on types.
|
||||
|
|
|
@ -9,8 +9,7 @@
|
|||
// We are temporarily importing the existing viewEngine_from core so we can be sure we are
|
||||
// correctly implementing its interfaces for backwards compatibility.
|
||||
|
||||
import {InjectionToken} from '../di/injection_token';
|
||||
import {Type} from '../interface/type';
|
||||
import {ProviderToken} from '../di/provider_token';
|
||||
import {createElementRef, ElementRef as ViewEngine_ElementRef, unwrapElementRef} from '../linker/element_ref';
|
||||
import {QueryList} from '../linker/query_list';
|
||||
import {createTemplateRef, TemplateRef as ViewEngine_TemplateRef} from '../linker/template_ref';
|
||||
|
@ -88,7 +87,7 @@ class LQueries_ implements LQueries {
|
|||
|
||||
class TQueryMetadata_ implements TQueryMetadata {
|
||||
constructor(
|
||||
public predicate: Type<any>|InjectionToken<unknown>|string[], public flags: QueryFlags,
|
||||
public predicate: ProviderToken<unknown>|string[], public flags: QueryFlags,
|
||||
public read: any = null) {}
|
||||
}
|
||||
|
||||
|
@ -456,7 +455,7 @@ export function ɵɵqueryRefresh(queryList: QueryList<any>): boolean {
|
|||
* @codeGenApi
|
||||
*/
|
||||
export function ɵɵviewQuery<T>(
|
||||
predicate: Type<any>|InjectionToken<unknown>|string[], flags: QueryFlags, read?: any): void {
|
||||
predicate: ProviderToken<unknown>|string[], flags: QueryFlags, read?: any): void {
|
||||
ngDevMode && assertNumber(flags, 'Expecting flags');
|
||||
const tView = getTView();
|
||||
if (tView.firstCreatePass) {
|
||||
|
@ -481,8 +480,8 @@ export function ɵɵviewQuery<T>(
|
|||
* @codeGenApi
|
||||
*/
|
||||
export function ɵɵcontentQuery<T>(
|
||||
directiveIndex: number, predicate: Type<any>|InjectionToken<unknown>|string[],
|
||||
flags: QueryFlags, read?: any): void {
|
||||
directiveIndex: number, predicate: ProviderToken<unknown>|string[], flags: QueryFlags,
|
||||
read?: any): void {
|
||||
ngDevMode && assertNumber(flags, 'Expecting flags');
|
||||
const tView = getTView();
|
||||
if (tView.firstCreatePass) {
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
|
||||
/* clang-format off */
|
||||
import {
|
||||
AbstractType,
|
||||
Component,
|
||||
Directive,
|
||||
InjectFlags,
|
||||
|
@ -22,6 +21,7 @@ import {
|
|||
NgZone,
|
||||
Pipe,
|
||||
PlatformRef,
|
||||
ProviderToken,
|
||||
Type,
|
||||
ɵflushModuleScopingQueueAsMuchAsPossible as flushModuleScopingQueueAsMuchAsPossible,
|
||||
ɵRender3ComponentFactory as ComponentFactory,
|
||||
|
@ -156,19 +156,14 @@ export class TestBedRender3 implements TestBed {
|
|||
return TestBedRender3 as any as TestBedStatic;
|
||||
}
|
||||
|
||||
static inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
static inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T
|
||||
|null;
|
||||
static inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T|null,
|
||||
flags?: InjectFlags): T|null {
|
||||
static inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
static inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T|null;
|
||||
static inject<T>(token: ProviderToken<T>, notFoundValue?: T|null, flags?: InjectFlags): T|null {
|
||||
return _getTestBedRender3().inject(token, notFoundValue, flags);
|
||||
}
|
||||
|
||||
/** @deprecated from v9.0.0 use TestBed.inject */
|
||||
static get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
static get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
/** @deprecated from v9.0.0 use TestBed.inject */
|
||||
static get(token: any, notFoundValue?: any): any;
|
||||
/** @deprecated from v9.0.0 use TestBed.inject */
|
||||
|
@ -263,14 +258,9 @@ export class TestBedRender3 implements TestBed {
|
|||
return this.compiler.compileComponents();
|
||||
}
|
||||
|
||||
inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T
|
||||
|null;
|
||||
inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T|null,
|
||||
flags?: InjectFlags): T|null {
|
||||
inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T|null;
|
||||
inject<T>(token: ProviderToken<T>, notFoundValue?: T|null, flags?: InjectFlags): T|null {
|
||||
if (token as unknown === TestBedRender3) {
|
||||
return this as any;
|
||||
}
|
||||
|
@ -281,7 +271,7 @@ export class TestBedRender3 implements TestBed {
|
|||
}
|
||||
|
||||
/** @deprecated from v9.0.0 use TestBed.inject */
|
||||
get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
/** @deprecated from v9.0.0 use TestBed.inject */
|
||||
get(token: any, notFoundValue?: any): any;
|
||||
/** @deprecated from v9.0.0 use TestBed.inject */
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AbstractType, ApplicationInitStatus, CompilerOptions, Component, Directive, InjectFlags, InjectionToken, Injector, NgModule, NgModuleFactory, NgModuleRef, NgZone, Optional, Pipe, PlatformRef, Provider, SchemaMetadata, SkipSelf, StaticProvider, Type, ɵclearOverrides as clearOverrides, ɵDepFlags as DepFlags, ɵgetInjectableDef as getInjectableDef, ɵINJECTOR_SCOPE as INJECTOR_SCOPE, ɵivyEnabled as ivyEnabled, ɵNodeFlags as NodeFlags, ɵoverrideComponentView as overrideComponentView, ɵoverrideProvider as overrideProvider, ɵstringify as stringify, ɵɵInjectableDeclaration} from '@angular/core';
|
||||
import {ApplicationInitStatus, CompilerOptions, Component, Directive, InjectFlags, InjectionToken, Injector, NgModule, NgModuleFactory, NgModuleRef, NgZone, Optional, Pipe, PlatformRef, Provider, ProviderToken, SchemaMetadata, SkipSelf, StaticProvider, Type, ɵclearOverrides as clearOverrides, ɵDepFlags as DepFlags, ɵgetInjectableDef as getInjectableDef, ɵINJECTOR_SCOPE as INJECTOR_SCOPE, ɵivyEnabled as ivyEnabled, ɵNodeFlags as NodeFlags, ɵoverrideComponentView as overrideComponentView, ɵoverrideProvider as overrideProvider, ɵstringify as stringify, ɵɵInjectableDeclaration} from '@angular/core';
|
||||
|
||||
import {AsyncTestCompleter} from './async_test_completer';
|
||||
import {ComponentFixture} from './component_fixture';
|
||||
|
@ -53,14 +53,11 @@ export interface TestBed {
|
|||
|
||||
compileComponents(): Promise<any>;
|
||||
|
||||
inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T
|
||||
|null;
|
||||
inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T|null;
|
||||
|
||||
/** @deprecated from v9.0.0 use TestBed.inject */
|
||||
get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
/** @deprecated from v9.0.0 use TestBed.inject */
|
||||
get(token: any, notFoundValue?: any): any;
|
||||
|
||||
|
@ -216,19 +213,14 @@ export class TestBedViewEngine implements TestBed {
|
|||
return TestBedViewEngine as any as TestBedStatic;
|
||||
}
|
||||
|
||||
static inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
static inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T
|
||||
|null;
|
||||
static inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T|null,
|
||||
flags?: InjectFlags): T|null {
|
||||
static inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
static inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T|null;
|
||||
static inject<T>(token: ProviderToken<T>, notFoundValue?: T|null, flags?: InjectFlags): T|null {
|
||||
return _getTestBedViewEngine().inject(token, notFoundValue, flags);
|
||||
}
|
||||
|
||||
/** @deprecated from v9.0.0 use TestBed.inject */
|
||||
static get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
static get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
/**
|
||||
* @deprecated from v9.0.0 use TestBed.inject
|
||||
* @suppress {duplicate}
|
||||
|
@ -469,14 +461,9 @@ export class TestBedViewEngine implements TestBed {
|
|||
}
|
||||
}
|
||||
|
||||
inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T
|
||||
|null;
|
||||
inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T|null,
|
||||
flags?: InjectFlags): T|null {
|
||||
inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T|null;
|
||||
inject<T>(token: ProviderToken<T>, notFoundValue?: T|null, flags?: InjectFlags): T|null {
|
||||
this._initIfNeeded();
|
||||
if (token as unknown === TestBed) {
|
||||
return this as any;
|
||||
|
@ -490,7 +477,7 @@ export class TestBedViewEngine implements TestBed {
|
|||
}
|
||||
|
||||
/** @deprecated from v9.0.0 use TestBed.inject */
|
||||
get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
/** @deprecated from v9.0.0 use TestBed.inject */
|
||||
get(token: any, notFoundValue?: any): any;
|
||||
/** @deprecated from v9.0.0 use TestBed.inject */
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AbstractType, Component, Directive, InjectFlags, InjectionToken, NgModule, Pipe, PlatformRef, SchemaMetadata, Type} from '@angular/core';
|
||||
import {Component, Directive, InjectFlags, InjectionToken, NgModule, Pipe, PlatformRef, ProviderToken, SchemaMetadata, Type} from '@angular/core';
|
||||
|
||||
import {ComponentFixture} from './component_fixture';
|
||||
import {MetadataOverride} from './metadata_override';
|
||||
|
@ -114,14 +114,11 @@ export interface TestBedStatic {
|
|||
deps?: any[],
|
||||
}): TestBedStatic;
|
||||
|
||||
inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
inject<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T
|
||||
|null;
|
||||
inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T|null;
|
||||
|
||||
/** @deprecated from v9.0.0 use TestBed.inject */
|
||||
get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
||||
/** @deprecated from v9.0.0 use TestBed.inject */
|
||||
get(token: any, notFoundValue?: any): any;
|
||||
|
||||
|
|
|
@ -6,14 +6,12 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AbstractType, inject, InjectFlags, InjectionToken, Injector, Type, ɵsetCurrentInjector as setCurrentInjector} from '@angular/core';
|
||||
import {inject, InjectFlags, InjectionToken, Injector, ProviderToken, ɵsetCurrentInjector as setCurrentInjector} from '@angular/core';
|
||||
|
||||
class MockRootScopeInjector implements Injector {
|
||||
constructor(readonly parent: Injector) {}
|
||||
|
||||
get<T>(
|
||||
token: Type<T>|AbstractType<T>|InjectionToken<T>, defaultValue?: any,
|
||||
flags: InjectFlags = InjectFlags.Default): T {
|
||||
get<T>(token: ProviderToken<T>, defaultValue?: any, flags: InjectFlags = InjectFlags.Default): T {
|
||||
if ((token as any).ɵprov && (token as any).ɵprov.providedIn === 'root') {
|
||||
const old = setCurrentInjector(this);
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue