pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://angular.dev/api/core/Injector

| (theme === 'auto' && prefersDark)) { documentClassList.add(DARK_MODE_CLASS_NAME); } else { documentClassList.add(LIGHT_MODE_CLASS_NAME); } if (location.search.includes('uwu')) { documentClassList.add('uwu'); } Injector • Angular
    • Overview
@angular/core

Injector

Class
stable

Concrete injectors implement this interface. Injectors are configured with providers that associate dependencies of various types with injection tokens.

API

    
      abstract class Injector {
}

get

4 overloads

Retrieves an instance from the injector based on the provided token.

@paramtokenProviderToken<T>
@paramnotFoundValueundefined
@paramoptionsInjectOptions & { optional?: false | undefined; }
@returnsT

The instance from the injector if defined, otherwise the notFoundValue.

Retrieves an instance from the injector based on the provided token.

@paramtokenProviderToken<T>
@paramnotFoundValuenull | undefined
@paramoptionsInjectOptions
@returnsT | null

The instance from the injector if defined, otherwise the notFoundValue.

Retrieves an instance from the injector based on the provided token.

@paramtokenProviderToken<T>
@paramnotFoundValueT | undefined
@paramoptionsInjectOptions | undefined
@returnsT

The instance from the injector if defined, otherwise the notFoundValue.

@deprecated

from v4.0.0 use ProviderToken

@paramtokenstring | ProviderToken<T>
@paramnotFoundValueany
@returnsany

create

2 overloads
@deprecated

from v5 use the new signature Injector.create(options)

@paramprovidersStaticProvider[]
@paramparentInjector | undefined
@returnsInjector

Creates a new injector instance that provides one or more dependencies, according to a given type or types of StaticProvider.

@paramoptions{ providers: (any[] | TypeProvider | ValueProvider | ClassProvider | ConstructorProvider | ExistingProvider | FactoryProvider | StaticClassProvider)[]; parent?: Injector | undefined; name?: string | undefined; }

An object with the following properties:

  • providers: An array of providers of the StaticProvider type.
  • parent: (optional) A parent injector.
  • name: (optional) A developer-defined identifying name for the new injector.
@returnsDestroyableInjector

The new injector instance.

Usage Notes

The following example creates a service injector instance.

class Square {
          name = 'square';
        }

        const injector = Injector.create({providers: [{provide: Square, deps: []}]});

        const shape: Square = injector.get(Square);
        expect(shape.name).toEqual('square');
        expect(shape instanceof Square).toBe(true);

Usage example

const injector: Injector = Injector.create({
        providers: [{provide: 'validToken', useValue: 'Value'}],
      });
      expect(injector.get('validToken')).toEqual('Value');
      expect(() => injector.get('invalidToken')).toThrowError();
      expect(injector.get('invalidToken', 'notFound')).toEqual('notFound');

Injector returns itself when given Injector as a token:

const injector = Injector.create({providers: []});
      expect(injector.get(Injector)).toBe(injector);
Jump to details
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy