Skip to content

Instantly share code, notes, and snippets.

@considine
Created October 9, 2018 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save considine/96425ad5c17ac179a9ffd680afd76ef0 to your computer and use it in GitHub Desktop.
Save considine/96425ad5c17ac179a9ffd680afd76ef0 to your computer and use it in GitHub Desktop.
import { Component, OnInit } from "@angular/core";
import { ActivatedRoute, ParamMap } from "@angular/router";
import { Observable } from "rxjs";
import { switchMap } from "rxjs/operators";
import { PostsService } from "./../posts.service";
@Component({
selector: "app-post-detail",
templateUrl: "./post-detail.page.html",
styleUrls: ["./post-detail.page.scss"]
})
export class PostDetailPage implements OnInit {
constructor(private route: ActivatedRoute, private postSrvc: PostsService) {}
post$: Observable<any>;
ngOnInit() {
this.post$ = this.route.paramMap.pipe(
switchMap((params: ParamMap) => this.postSrvc.fetchPost(params.get("id")))
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment