import { Component, OnInit, ViewChild } from '@angular/core'; import { HeaderFooter } from '../setting.class'; import { SettingServices } from '../setting.services'; import { NotificationService } from '../../../_services/notification.service'; import { LocalService } from '../../../_services/local.service'; import { FormCanDeactivate } from '../../../_guards/form-can-deactivate'; import { NgForm } from '@angular/forms'; @Component({ selector: 'app-header-footer', templateUrl: './header-footer.component.html', }) export class HeaderFooterComponent extends FormCanDeactivate implements OnInit { @ViewChild('f') form: NgForm; public obj: HeaderFooter = new HeaderFooter(); public saving = false; public nowDate = new Date(); constructor( private settingServices: SettingServices, private _notificationService: NotificationService, private _localService: LocalService ) { super(); } ngOnInit() { this.getHeaderFooter(); } public onSubmit() { this.saving = true; this.settingServices.saveHeaderFootrer(this.obj).subscribe((res: any) => { if (res) { this.obj = res; } this.saving = false; this._notificationService.notify("success", "Save Successfully!"); }, err => { this._notificationService.notify("danger", err.error.msg); }); } public attachfile(event) { this.obj.file = event.target.files[0]; } public getHeaderFooter() { this.settingServices.getHeaderFooter().subscribe((res: any) => { if (res) { this.obj = res; } }, err => { this._notificationService.notify("danger", err.error.msg); }); } }