import { Component , OnDestroy , OnInit } from '@angular/core' ; import { TagService } from "./services/tag.service" ; import { ErrFmt } from "../util/helpers/err.helper" ; import { ActivatedRoute , Params } from "@angular/router" ; import { ToastComponent } from "../shared/toast/toast.component" ; import * as moment from 'moment' ; import * as _ from "lodash" ; @ Component ( { selector : 'app-tag-post-list' , templateUrl : './tag.post.list.component.html' , styleUrls : [ './tag.post.list.component.scss' ] } ) export class TagPostListComponent implements OnInit , OnDestroy { sub : any ; posts : any = [ ] ; _id : string ; isLoading = true ; constructor ( private tagService , private route , public toast ) { } ngOnInit ( ) { this . sub = this . route . params . subscribe ( ( params ) => { this . _id = params [ '_id' ] ; } ) ; this . getTagPosts ( ) ; } ngOnDestroy ( ) { this . sub . unsubscribe ( ) ; } private getTagPosts ( page = null ) { this . tagService . getTagPosts ( this . _id , page ) . subscribe ( data => this . posts = data , error => this . toast . setMessage ( ErrFmt ( error ) , 'danger' ) , ( ) => this . isLoading = false ) ; } setPage ( page ) { this . getTagPosts ( page ) ; } getRange ( lastPage ) { return _ . range ( 1 , lastPage + 1 ) ; } timeAgo ( created_at ) { return moment ( parseInt ( created_at , 10 ) ) . fromNow ( ) ; } }