feat: tree-shakeable providers API updates (#22655)
Rename @Injectable({scope -> providedIn}). Instead of {providedIn: APP_ROOT_SCOPE}, accept {providedIn: 'root'}. Also, {providedIn: null} implies the injectable should not be added to any scope. PR Close #22655
This commit is contained in:

committed by
Kara Erickson

parent
21e44c6ba9
commit
db56836425
@ -35,7 +35,7 @@ export class AppComponent {
|
||||
export class DepAppModule {
|
||||
}
|
||||
|
||||
@Injectable({scope: DepAppModule})
|
||||
@Injectable({providedIn: DepAppModule})
|
||||
export class ShakeableService {
|
||||
constructor(readonly normal: NormalService) {}
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {APP_ROOT_SCOPE, Component, Injectable, NgModule, Optional, Self} from '@angular/core';
|
||||
import {Component, Injectable, NgModule, Optional, Self} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {ServerModule} from '@angular/platform-server';
|
||||
import {RouterModule} from '@angular/router';
|
||||
|
@ -6,10 +6,10 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {APP_ROOT_SCOPE, Injectable} from '@angular/core';
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
scope: APP_ROOT_SCOPE,
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class Service {
|
||||
}
|
||||
|
@ -36,6 +36,6 @@ export class AppComponent {
|
||||
export class SelfAppModule {
|
||||
}
|
||||
|
||||
@Injectable({scope: SelfAppModule})
|
||||
@Injectable({providedIn: SelfAppModule})
|
||||
export class ShakeableService {
|
||||
}
|
@ -32,7 +32,7 @@ export class AppComponent {
|
||||
export class StringAppModule {
|
||||
}
|
||||
|
||||
@Injectable({scope: StringAppModule})
|
||||
@Injectable({providedIn: StringAppModule})
|
||||
export class Service {
|
||||
constructor(@Inject('someStringToken') readonly data: string) {}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ export class TokenModule {
|
||||
}
|
||||
|
||||
export const TOKEN = new InjectionToken('test', {
|
||||
scope: TokenModule,
|
||||
providedIn: TokenModule,
|
||||
factory: () => new Service(inject(Dep)),
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user