You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

5 years ago
import { Component, OnInit } from '@angular/core'
import { Router, NavigationEnd, NavigationStart, ActivatedRoute } from '@angular/router'
5 years ago
import { Location } from '@angular/common'
import { ApisService } from '../services/apis.service'
@Component({
selector: 'app-detail',
templateUrl: './detail.component.html',
styleUrls: ['./detail.component.scss']
})
export class DetailComponent implements OnInit {
public details: any = {}
private history: string[] = []
5 years ago
constructor(
private apisService: ApisService,
private router: Router,
private location: Location,
private activeRoute: ActivatedRoute
) { }
5 years ago
ngOnInit(): void {
this.showDetails(this.router.url.split('/')[2], this.router.url.split('/')[3])
5 years ago
}
showDetails(section, id): void {
this.apisService.getDetails(section, id).toPromise().then((response) => {
if(this.history[this.history.length - 1] != `/detail/${section}/${id}`) {
this.history.push(`/detail/${section}/${id}`)
}
5 years ago
this.details = response.item
},(error) => {
console.error('getPortfolio ERROR', error)
}).catch((e) => {
console.error('getPortfolio CATCH', e)
})
}
back(): void {
this.history.pop()
if(this.history.length > 0) {
const last = this.history[this.history.length - 1]
this.showDetails(last.split('/')[2], last.split('/')[3])
this.location.back()
} else {
this.location.back()
}
5 years ago
}
}