import { Component, OnInit, OnDestroy } from '@angular/core'; import { NbWindowRef, // NbIconLibraries, } from '@nebular/theme'; import { ComponentOptions } from '../../../model/componets'; import { ComponentsService } from '../../../services/components.service'; @Component({ selector: 'ngx-component-form', templateUrl: './component-form.component.html', styleUrls: ['./component-form.component.scss'], }) export class ComponentFormComponent implements OnInit, OnDestroy { source: ComponentOptions; doSave = true; constructor( private componentsService: ComponentsService, public windowRef: NbWindowRef, ) {} ngOnInit() { this.source = this.windowRef.config.context as ComponentOptions; } ngOnDestroy(): void { if (this.doSave) { this.save(); } } submit() { this.close(); } close() { this.windowRef.close(); } deleteComponent() { this.componentsService.deleteLocalComponent(); this.doSave = false; this.close(); } save() { this.componentsService.addComponent().then((result) => { // 成功 // console.log('component saved'); }).catch((err) => { // 失败 }); } }