Created
September 19, 2019 21:56
-
-
Save oleersoy/a3a31037db8c81ced8bebb0cdd2e7207 to your computer and use it in GitHub Desktop.
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 { Injectable } from '@angular/core'; | |
import { | |
Resolve, | |
ActivatedRouteSnapshot, | |
RouterStateSnapshot } from '@angular/router'; | |
import { Post } from './post.model'; | |
import { HttpClient } from '@angular/common/http'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class PostResolverService implements Resolve<Post> { | |
constructor(private http:HttpClient) { } | |
async resolve(route: ActivatedRouteSnapshot) { | |
const id = route.paramMap.get('id'); | |
const post = await this.http.get<Post>(`/assets/posts/${id}.json`).toPromise(); | |
return new Post(post.title, post.content); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment