docs: clean up providedIn: 'root' syntax for router examples (#20023)
PR Close #20023
This commit is contained in:
parent
ac5aa8f46d
commit
0aafbac99b
|
@ -1,10 +1,9 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||||||
import { Observable } from 'rxjs/Observable';
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class AuthGuard implements CanActivate {
|
export class AuthGuard implements CanActivate {
|
||||||
canActivate(
|
canActivate(
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
|
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
|
||||||
import { Observable } from 'rxjs/Observable';
|
|
||||||
|
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class AuthGuard implements CanActivate {
|
export class AuthGuard implements CanActivate {
|
||||||
constructor(private authService: AuthService, private router: Router) {}
|
constructor(private authService: AuthService, private router: Router) {}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class AuthGuard implements CanActivate, CanActivateChild {
|
export class AuthGuard implements CanActivate, CanActivateChild {
|
||||||
constructor(private authService: AuthService, private router: Router) {}
|
constructor(private authService: AuthService, private router: Router) {}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class AuthGuard implements CanActivate, CanActivateChild {
|
export class AuthGuard implements CanActivate, CanActivateChild {
|
||||||
constructor(private authService: AuthService, private router: Router) {}
|
constructor(private authService: AuthService, private router: Router) {}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class AuthGuard implements CanActivate, CanActivateChild, CanLoad {
|
export class AuthGuard implements CanActivate, CanActivateChild, CanLoad {
|
||||||
constructor(private authService: AuthService, private router: Router) {}
|
constructor(private authService: AuthService, private router: Router) {}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { Observable, of } from 'rxjs';
|
||||||
import { tap, delay } from 'rxjs/operators';
|
import { tap, delay } from 'rxjs/operators';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
isLoggedIn = false;
|
isLoggedIn = false;
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { CanDeactivate,
|
||||||
import { CrisisDetailComponent } from './crisis-center/crisis-detail/crisis-detail.component';
|
import { CrisisDetailComponent } from './crisis-center/crisis-detail/crisis-detail.component';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class CanDeactivateGuard implements CanDeactivate<CrisisDetailComponent> {
|
export class CanDeactivateGuard implements CanDeactivate<CrisisDetailComponent> {
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ export interface CanComponentDeactivate {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
|
export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
|
||||||
canDeactivate(component: CanComponentDeactivate) {
|
canDeactivate(component: CanComponentDeactivate) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class CrisisDetailResolverService {
|
export class CrisisDetailResolverService {
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
|
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Router, Resolve, RouterStateSnapshot,
|
import {
|
||||||
ActivatedRouteSnapshot } from '@angular/router';
|
Router, Resolve,
|
||||||
import { Observable, of, EMPTY as empty } from 'rxjs';
|
RouterStateSnapshot,
|
||||||
import { mergeMap, take } from 'rxjs/operators';
|
ActivatedRouteSnapshot
|
||||||
|
} from '@angular/router';
|
||||||
|
import { Observable, of, EMPTY } from 'rxjs';
|
||||||
|
import { mergeMap, take } from 'rxjs/operators';
|
||||||
|
|
||||||
import { CrisisService } from './crisis.service';
|
import { CrisisService } from './crisis.service';
|
||||||
import { Crisis } from './crisis';
|
import { Crisis } from './crisis';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class CrisisDetailResolverService implements Resolve<Crisis> {
|
export class CrisisDetailResolverService implements Resolve<Crisis> {
|
||||||
constructor(private cs: CrisisService, private router: Router) {}
|
constructor(private cs: CrisisService, private router: Router) {}
|
||||||
|
@ -25,7 +28,7 @@ export class CrisisDetailResolverService implements Resolve<Crisis> {
|
||||||
return of(crisis);
|
return of(crisis);
|
||||||
} else { // id not found
|
} else { // id not found
|
||||||
this.router.navigate(['/crisis-center']);
|
this.router.navigate(['/crisis-center']);
|
||||||
return empty;
|
return EMPTY;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { Crisis } from './crisis';
|
||||||
import { CRISES } from './mock-crises';
|
import { CRISES } from './mock-crises';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class CrisisService {
|
export class CrisisService {
|
||||||
static nextCrisisId = 100;
|
static nextCrisisId = 100;
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { Observable, of } from 'rxjs';
|
||||||
* TODO: better modal implementation that doesn't use window.confirm
|
* TODO: better modal implementation that doesn't use window.confirm
|
||||||
*/
|
*/
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class DialogService {
|
export class DialogService {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { PreloadingStrategy, Route } from '@angular/router';
|
||||||
import { Observable, of } from 'rxjs';
|
import { Observable, of } from 'rxjs';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class SelectivePreloadingStrategyService implements PreloadingStrategy {
|
export class SelectivePreloadingStrategyService implements PreloadingStrategy {
|
||||||
preloadedModules: string[] = [];
|
preloadedModules: string[] = [];
|
||||||
|
|
Loading…
Reference in New Issue