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
Name | Type |
---|---|
T | extends Constructor |
Parameters
Name | Type |
---|---|
options? | InjectableOptions |
Returns
fn
▸ (target
): void
Parameters
Name | Type |
---|---|
target | T |
Returns
void