explore-services/portal-2/src/app/landingPages/person/person.component.ts

61 lines
1.6 KiB
TypeScript

import {Component} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import { ActivatedRoute } from '@angular/router';
import {PersonService} from '../../services/person.service';
import { PersonInfo } from '../../utils/entities/personInfo';
@Component({
selector: 'person',
templateUrl: 'person.component.html',
})
export class PersonComponent {
constructor (private _personService: PersonService,
private route: ActivatedRoute) {
console.info('person constructor');
}
ngOnInit() {
console.info('person init');
this.sub = this.route.queryParams.subscribe(params => {
this.personId = params['personId'];
console.info("Id is :"+this.personId);
if(this.personId){
this.getPersonInfo();
}else{
this.warningMessage="No valid project id";
}
});
}
personInfo: PersonInfo;
private personId: string;
public warningMessage = "";
public errorMessage = "";
ngOnDestroy() {
this.sub.unsubscribe();
}
sub: any;
private getPersonInfo () {
console.info("inside getProjectInfo of component");
this.warningMessage = '';
this.errorMessage=""
console.info("do request");
this._personService.getPersonInfo(this.personId).subscribe(
data => {
this.personInfo = data;
},
err => {
console.error(err)
console.info("error");
this.errorMessage = 'No person found';
}
);
}
}