import { Component, OnInit } from '@angular/core'; import * as moment_ from 'moment'; import { DatePipe } from '@angular/common' import { JobplanServicesService } from '../../shared/services/jobplan-services.service'; const moment = moment_; @Component({ selector: 'app-job-plan-detail', templateUrl: './job-plan-detail.component.html', styleUrls: ['./job-plan-detail.component.css'], providers:[DatePipe] }) export class JobPlanDetailComponent implements OnInit { JopPlanDetails: any = []; startDateValue: any; dueDateValue: any; Instructions: any; JobPlanId: any; // Display date time displayDate: any; constructor(private jopPlanService: JobplanServicesService, public datepipe: DatePipe) { } ngOnInit() { } getJobPlanById(JobPlanId) { this.jopPlanService.getJobPlanById(JobPlanId) .subscribe(res => { console.log('Job Plan details', res); this.JopPlanDetails = res[0]; this.JobPlanId = this.JopPlanDetails.JobPlanId; this.startDateValue = moment(this.JopPlanDetails.StartDate).toDate(); this.dueDateValue = moment(this.JopPlanDetails.EndDate).toDate(); this.Instructions = this.JopPlanDetails.Instructions; // Convet date formate // this.startDateValue =this.datepipe.transform(this.startDateValue, 'dd/MM/yyyy h:mm:ss a (z)'); // this.dueDateValue =this.datepipe.transform(this.dueDateValue, 'dd/MM/yyyy h:mm:ss a (z)'); this.startDateValue =this.datepipe.transform(this.startDateValue, 'yyyy-MM-dd'); this.startDateValue = this.startDateValue + 'T' + this.JopPlanDetails.StartTime; this.startDateValue = this.datepipe.transform(this.startDateValue, 'dd/MM/yyyy h:mm:ss a (z)'); this.dueDateValue =this.datepipe.transform(this.dueDateValue, 'yyyy-MM-dd'); this.dueDateValue = this.dueDateValue + 'T' + this.JopPlanDetails.EndTime; this.dueDateValue = this.datepipe.transform(this.dueDateValue, 'dd/MM/yyyy h:mm:ss a (z)'); }, error => console.log('Error', error)); } updateInstructions() { const jobplan = [{ JobPlanId: this.JobPlanId, Instructions: this.Instructions, }] ; this.jopPlanService.updateJobPlan(jobplan) .subscribe(() => { console.log('Get job plan by id', this.startDateValue); }, error => console.log('Error', error)); } }