我能够收集initialState
对象中传递的数据,例如在这段代码中:
const initialState = {
titulo: titulo,
origen: origen,
th1: "Número",
th2: "Nombres",
modalFor: "Locales"
};
this.bsModalRef = this.modalService.show(ClienteOlocalPopUpComponent, {
initialState,
backdrop: "static",
keyboard: false
});
并在 ClienteOlocalPopUpComponent.html 中插入其属性。
但是,如果我希望传递给模态的值const initialState
是,比方说,在 ClienteOlocalPopUpComponent.ts 的方法中打印在控制台中ngOnInit()
¿我怎样才能做到这一点?在模态的 .ts 文件中无法识别。
谢谢。
这是启动模式的组件的代码:
openModal(origen, titulo) {
this.origen = origen;
if (origen === "cliente") {
const initialState = {
titulo: titulo,
origen: origen,
th1: "RUT",
th2: "Nombres",
modalFor: "Clientes",
rutClientes: this.requestTres.rutCliente,
rutOperador: this.requestTres.rutOperador
};
this.bsModalRef = this.modalService.show(ClienteOlocalPopUpComponent, {
initialState,
backdrop: "static",
keyboard: false
});
}
else if (origen === "local") {
if (!this.forma.controls.rutCliente.value) {
swal("Seleccione un cliente", "", "warning");
} else {
// tslint:disable-next-line: max-line-length / crecion del request para locales
this.documentosService.localRequest.rutCliente = this.requestTres.rutCliente = parseInt(
this.forma.controls.rutCliente.value.toString().slice(0, -1),
10
);
this.documentosService.localRequest.rutOperador = this.rutOperador;
let initialState = {
titulo: titulo,
origen: origen,
th1: "Número",
th2: "Nombres",
modalFor: "Locales",
rutClientes: this.requestTres.rutCliente,
rutOperador: this.requestTres.rutOperador
};
this.bsModalRef = this.modalService.show(ClienteOlocalPopUpComponent, {
initialState,
backdrop: "static",
keyboard: false
});
}
}
}
这是模态的 .ts :
import { DocumentosService } from './../../../core/consultaService/documentos.service';
import { Component, OnInit } from '@angular/core';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { ConsultasService } from '../../../core/consultaService/consultas.service';
import {
FormGroup,
FormBuilder,
Validators,
FormControl
} from '@angular/forms';
import { ClientesService } from '../../../core/consultaService/clientes.service';
@Component({
selector: 'app-cliente-o-local-pop-up',
templateUrl: './clienteOlocalPopUp.component.html',
styleUrls: ['./clienteOlocalPopUp.component.scss']
})
export class ClienteOlocalPopUpComponent implements OnInit {
origen: string;
titulo: string;
forma: FormGroup;
forma2: FormGroup;
clientes: any;
clientesData: any;
cliente: any;
cargando = false;
constructor(
public bsModalRef: BsModalRef,
private clientesService: ClientesService,
private consultasService: ConsultasService,
private documentosService: DocumentosService
) {
this.forma2 = new FormGroup({
nombreCliente: new FormControl(),
modalFor: new FormControl()
});
}
ngOnInit() {
console.log(this.initialState); // initiaState is highlighted as if does not exist.
}
}
initialState
被高亮显示,就好像它不存在一样,尽管它被传入了。