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
const routes = [ | |
{ | |
path: 'login', | |
component: LoginPageComponent, | |
canMatch: [authGuard({ isProtected: false })], | |
}, | |
{ | |
path: 'todos', | |
component: TodosPageComponent, | |
canMatch: [authGuard()], |
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
import { inject } from '@angular/core'; | |
import { CanMatchFn, Router } from '@angular/router'; | |
import { AuthService } from './auth-service'; | |
export function authGuard({ | |
redirectTo, | |
isProtected = true, | |
}: { | |
redirectTo?: any[]; | |
isProtected?: boolean; |
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
const routes = [ | |
{ | |
path: 'somePath', | |
component: EditCmp, | |
canDeactivate: [(component: EditCmp) => !component.hasUnsavedChanges], | |
}, | |
{ path: 'somePath', canActivate: [() => inject(MyDependency).canActivate()] }, | |
]; |
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
import { repeat } from 'rxjs'; | |
@Injectable({ providedIn: 'root' }) | |
export class MetricsService { | |
private http = inject(HttpClient); | |
getMetrics() { | |
return this.http.get('https://metrics') | |
.pipe( | |
repeat({ delay: 30_000 }), |
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
import { repeat, filter, take, timer } from 'rxjs'; | |
@Injectable({ providedIn: 'root' }) | |
export class FooService { | |
private http = inject(HttpClient); | |
doSometing(data) { | |
return this.http.post('https://foo', data) | |
.pipe( | |
// 👇👇👇 |
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
import { repeat, filter, take } from 'rxjs'; | |
@Injectable({ providedIn: 'root' }) | |
export class FooService { | |
private http = inject(HttpClient); | |
doSometing(data) { | |
return this.http.post('https://foo', data) | |
.pipe( | |
repeat({ delay: 1000 }), |
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
import { repeat } from 'rxjs'; | |
@Injectable({ providedIn: 'root' }) | |
export class MetricsService { | |
private http = inject(HttpClient); | |
getMetrics() { | |
return this.http.get('https://metrics') | |
.pipe( | |
repeat({ delay: 30_000 }), |
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
bootstrapApplication(AppComponent, { | |
providers: [ | |
provideHttpClient( | |
withInterceptors([ | |
(req, next) => { | |
console.log('Global interceptor'); | |
return next(req); | |
}, | |
]) | |
), |
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
import { | |
HTTP_INTERCEPTORS, | |
provideHttpClient, | |
withInterceptors, | |
withInterceptorsFromDi, | |
} from '@angular/common/http'; | |
import { bootstrapApplication } from '@angular/platform-browser'; | |
bootstrapApplication(AppComponent, { | |
providers: [ |
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
import { | |
provideHttpClient, | |
withInterceptors | |
} from '@angular/common/http'; | |
import { bootstrapApplication } from '@angular/platform-browser'; | |
bootstrapApplication(AppComponent, { | |
providers: [ | |
provideHttpClient( | |
withInterceptors([ |
NewerOlder