Skip to main content

Function: Injectable

Injectable<T>(options?): (target: T) => void

Decorator that marks a class providable as a dependency.

Use the providedIn option to provide the dependency in the root injector.

Example

Mark MyService as a dependency in a component.

@Injectable()
class MyService {
doSomething() {
console.log("Hello World!");
}
}

@MnComponent({
scope: {
pageType: "record"
},
providers: [
MyService
]
})
export class MyComponent {
constructor(myService: MyService) {
myService.doSomething();
}
}

Example

Mark MyService as a dependency and provide it in the root injector.

@Injectable({
providedIn: "root"
})
class MyService {
doSomething() {
console.log("Hello World!");
}
}

@MnComponent({
scope: {
pageType: "record"
}
})
export class MyComponent {
constructor(myService: MyService) {
myService.doSomething();
}
}

Type parameters

NameType
Textends Constructor

Parameters

NameType
options?InjectableOptions

Returns

fn

▸ (target): void

Parameters
NameType
targetT
Returns

void

Defined in

packages/core/src/core/di/injectable.ts:69