Function: Inject
▸ Inject(serviceIdentifier
): (target
: DecoratorTarget
<unknown
>, targetKey?
: string
| symbol
, indexOrPropertyDescriptor?
: number
| TypedPropertyDescriptor
<any
>) => void
Decorator on a dependency that specifies the identifier for that dependency.
Example
Inject MyService
into MyComponent
using the identifier (token) "ServiceIdentifier".
interface Service {
doSomething(): void;
}
@Injectable()
class MyService implements Service {
doSomething() {
console.log("Hello World!");
}
}
@MnComponent({
providers: [
{ provide: "ServiceIdentifier", useClass: MyService }
]
})
export class MyComponent {
// Search for a dependency with the identifier "ServiceIdentifier" and inject it into this property.
@Inject("ServiceIdentifier")
myService: Service;
}
Parameters
Name | Type | Description |
---|---|---|
serviceIdentifier | any | Identifier of the dependency. |
Returns
fn
▸ (target
, targetKey?
, indexOrPropertyDescriptor?
): void
Parameters
Name | Type |
---|---|
target | DecoratorTarget <unknown > |
targetKey? | string | symbol |
indexOrPropertyDescriptor? | number | TypedPropertyDescriptor <any > |
Returns
void