Я создаю модальное событие clickRow из Ng-smartTable. У меня проблемы с передачей значения в мой модальный
. То, что у меня есть до сих пор, - это захват значения и построение модального режима, я использую NbDialogService из Nebular Theme. Я также пытался работать с @Input - HTML -
<ng2-smart-table [settings]="settings"
[source]="source"
(userRowSelect)=onUserRowSelect($event)>
</ng2-smart-table>
- Компонент таблицы -
public onUserRowSelect(event) {
const idRegister = event.data.id;
this.nbService.open(ReportModalComponent);
}
- Модал -
import {Component, Input, OnInit} from '@angular/core';
import {ProductLoseService} from '../../Utils/Service/product-lose.service';
import {FormBuilder, FormGroup } from '@angular/forms';
@Component({
selector: 'ngx-report-modal',
templateUrl: './report-modal.component.html',
styleUrls: ['./report-modal.component.scss'],
})
export class ReportModalComponent implements OnInit {
form: FormGroup;
@Input()
idRegister: number;
constructor(public fb: FormBuilder,
private productLoseService: ProductLoseService) {
console.log(this.idRegister);
this.buildForm();
}
ngOnInit(): void {
this.populateModal();
}
private buildForm() {
this.form = this.fb.group({
id: [{value: '', disabled: true}],
codigoPerdida: [{value: '', disabled: true}],
fecha: [{value: '', disabled: true}],
cantidad: [{value: '', disabled: true}],
descripcion: [{value: '', disabled: true}],
detalleProducto: [{value: '', disabled: true}],
producto: [{value: '', disabled: true}],
lote: [{value: '', disabled: true}],
precio: [{value: '', disabled: true}],
estado: [{value: '', disabled: true}],
});
}
private populateModal() {
const params = {
idPerdida: 1,
};
this.productLoseService.getProductLose(params).subscribe(
response => {
const list = {
id: response[0].idPerdida,
codigoPerdida: response[0].codigo,
fecha: response[0].fecha,
cantidad: response[0].cantidad,
descripcion: response[0].descripcion,
detalleProducto: response[0].idDetalleProducto.idProductoDetalle,
producto: response[0].idDetalleProducto.idProducto.nombre,
lote: response[0].idDetalleProducto.idLote.idLote,
precio: response[0].idDetalleProducto.precio,
estado: response[0].estado.nombre,
};
this.populateInputs(list);
});
}
private populateInputs(list) {
this.form.setValue({
id: list.id,
codigoPerdida: list.codigoPerdida,
fecha: list.fecha,
cantidad: list.cantidad,
descripcion: list.descripcion,
detalleProducto: list.detalleProducto,
producto: list.producto,
lote: list.lote,
precio: list.precio,
estado: list.estado,
});
}
public onSubmit(event) {
if (window.confirm('¿Aprueba el siguiente reporte de pérdida?')) {
event.confirm.resolve();
} else {
event.confirm.reject();
}
}
}