penambahan modal add device

This commit is contained in:
2024-04-20 01:04:47 +07:00
parent dbc89d326f
commit 8f0c2fb913
11 changed files with 645 additions and 9 deletions

View File

@@ -0,0 +1,41 @@
import { Component, Input } from "@angular/core";
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
@Component({
selector: "app-modal-add-edit",
templateUrl: "./modal-add-edit.component.html",
styleUrls: ["./modal-add-edit.component.css"],
})
export class ModalAddEditComponent {
@Input() newAttribute: any = {};
myForm: FormGroup;
constructor(public activeModal: NgbActiveModal, private fb: FormBuilder) {
this.createForm();
}
createForm() {
this.myForm = this.fb.group({
name: ['', Validators.required],
position: ['', Validators.required],
age: [null, [Validators.required, Validators.min(18)]],
department: ['', Validators.required]
});
}
addRow() {
if (this.myForm.valid) {
this.activeModal.close(this.myForm.value);
}
}
addDepartment() {
// Example function to simulate adding a department
let newDept = prompt("Enter new department name:");
if (newDept) {
// Normally you would add to a database or a service
alert(`Department ${newDept} added! (simulated)`);
}
}
}