-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: update examples for tree-shakeable providers
- Loading branch information
Showing
25 changed files
with
154 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
aio/content/examples/dependency-injection/src/app/heroes/hero.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// #docregion | ||
import { NgModule } from '@angular/core'; | ||
|
||
@NgModule({}) | ||
export class HeroModule { | ||
} |
4 changes: 3 additions & 1 deletion
4
aio/content/examples/dependency-injection/src/app/heroes/hero.service.0.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
@Injectable() | ||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class HeroService { | ||
constructor() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
aio/content/examples/dependency-injection/src/app/heroes/hero.service.3.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// #docregion | ||
import { Injectable } from '@angular/core'; | ||
import { HEROES } from './mock-heroes'; | ||
|
||
@Injectable({ | ||
// we declare that this service should be created | ||
// by the root application injector. | ||
|
||
providedIn: 'root', | ||
}) | ||
export class HeroService { | ||
getHeroes() { return HEROES; } | ||
} |
14 changes: 14 additions & 0 deletions
14
aio/content/examples/dependency-injection/src/app/heroes/hero.service.4.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// #docregion | ||
import { Injectable } from '@angular/core'; | ||
import { HeroModule } from './hero.module'; | ||
import { HEROES } from './mock-heroes'; | ||
|
||
@Injectable({ | ||
// we declare that this service should be created | ||
// by any injector that includes HeroModule. | ||
|
||
providedIn: HeroModule, | ||
}) | ||
export class HeroService { | ||
getHeroes() { return HEROES; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
aio/content/examples/dependency-injection/src/app/heroes/heroes-tsp.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
/** | ||
* A version of `HeroesComponent` that does not provide the `HeroService` (and thus relies on its | ||
* `Injectable`-declared provider) in order to function. | ||
* | ||
* TSP stands for Tree-Shakeable Provider. | ||
*/ | ||
@Component({ | ||
selector: 'app-heroes-tsp', | ||
template: ` | ||
<h2>Heroes</h2> | ||
<app-hero-list></app-hero-list> | ||
` | ||
}) | ||
export class HeroesTspComponent { } |
15 changes: 15 additions & 0 deletions
15
aio/content/examples/dependency-injection/src/app/tree-shaking/app.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { RouterModule } from '@angular/router'; | ||
import { ServiceModule } from './service-and-module'; | ||
|
||
// #docregion | ||
@NgModule({ | ||
imports: [ | ||
BrowserModule, | ||
RouterModule.forRoot([]), | ||
ServiceModule, | ||
], | ||
}) | ||
export class AppModule { | ||
} |
14 changes: 14 additions & 0 deletions
14
aio/content/examples/dependency-injection/src/app/tree-shaking/service-and-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// #docregion | ||
import { Injectable, NgModule } from '@angular/core'; | ||
|
||
@Injectable() | ||
export class Service { | ||
doSomething(): void { | ||
} | ||
} | ||
|
||
@NgModule({ | ||
providers: [Service], | ||
}) | ||
export class ServiceModule { | ||
} |
11 changes: 11 additions & 0 deletions
11
aio/content/examples/dependency-injection/src/app/tree-shaking/service.0.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
// #docregion | ||
@Injectable({ | ||
providedIn: 'root', | ||
useFactory: () => new Service('dependency'), | ||
}) | ||
export class Service { | ||
constructor(private dep: string) { | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
aio/content/examples/dependency-injection/src/app/tree-shaking/service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
// #docregion | ||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class Service { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { NgModule } from '@angular/core'; | ||
|
||
import { UserService } from './user.service'; | ||
|
||
@NgModule({ | ||
providers: [UserService], | ||
}) | ||
export class UserModule { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class UserService { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { UserModule } from './user.module'; | ||
|
||
@Injectable({ | ||
providedIn: UserModule, | ||
}) | ||
export class UserService { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters