Skip to content

Instantly share code, notes, and snippets.

@taylorc
Created May 9, 2018 03:20
Show Gist options
  • Save taylorc/95fdcae69590ad89481f038a1a971b0e to your computer and use it in GitHub Desktop.
Save taylorc/95fdcae69590ad89481f038a1a971b0e to your computer and use it in GitHub Desktop.
view-posts.component.ts
import { Observable } from 'rxjs/Observable';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Select, Store } from '@ngxs/store';
import { FetchPosts } from '../../shared/posts/post.actions';
import { PostState } from '../../shared/posts/post.store';
@Component({
selector: 'app-view-posts',
templateUrl: './view-posts.component.html',
styleUrls: ['./view-posts.component.css']
})
export class ViewPostsComponent implements OnInit {
constructor(private store: Store, private route: ActivatedRoute) { }
@Select(PostState.loading) loading$: Observable<boolean>;
@Select(PostState.posts) posts$: Observable<Post[]>;
ngOnInit() {
this.store.dispatch(new FetchPosts());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment