У меня есть компонент, который я использовал в качестве диалога на своем основном компоненте. Он работает, но я должен знать, как отправить ему значение (объект), чтобы вставить его значения в мою форму, когда пользователь запускает диалоговое окно. (и если object = null, это делает форму понятной);
вот мой компонент
1 - основной компонент:
export class GestionDesChauffeursComponent implements OnInit {
constructor(private _fuseTranslationLoaderService: FuseTranslationLoaderService,
private service: GetionChauffeursService, private dialog: MatDialog) { this._fuseTranslationLoaderService.loadTranslations(english, turkish); }
Update_chauffeur(){
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.height = "570px";
dialogConfig.width = "550px";
this.dialog.open(EditNewChauffeursComponent,dialogConfig);
}
onEdit(row){
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = false;
dialogConfig.autoFocus = true;
dialogConfig.height = "570px";
dialogConfig.width = "550px";
//this.dialog.open(EditNewChauffeursComponent,dialogConfig);
this.dialog.open(EditNewChauffeursComponent,{
...dialogConfig,
data: {
// data I want to pass into the dialog
myVar: row
}
});
onDelete(key){
var index = index = this.listDriverElementEntity.map(x => {return x.key}).indexOf(key);
console.log(index);
this.listDriverElementEntity.splice(index, 1);
this.service.Removechauffeur(key).subscribe(data=>{
this.listdata = new MatTableDataSource(this.listDriverElementEntity);
console.log(data);
});
}
Rq: строка содержит объект моего datatable - это объект, который я отправлю при запуске функции onEdit.
Мой comip EditNewChauffeursComponent onet:
model: any = {};
profileForm = this.fb.group({
Nom_de_famille: ['', Validators.required],
Prénom: ['', Validators.required],
email: ['', [Validators.email,Validators.required]],
Code_personnel: ['', Validators.required],
N_tel: [''],
Département: ['', Validators.required]
});
constructor(public dialogRef: MatDialogRef<EditNewChauffeursComponent>, private fb: FormBuilder,private _snackBar: MatSnackBar,private service: GetionChauffeursService) { }
@Inject(MAT_DIALOG_DATA) indata: any
ngOnInit() {
console.log(this.indata);
}
setdefaultformvalues(row) {
this.profileForm.setValue({
Nom_de_famille: [row.FirstName],
Prénom: [row.LastName],
email: [row.Email],
Code_personnel: [row.DriverCode],
N_tel: [''],
Département: ['']
});
}
Я просто изменяю свой код, но 'indata' дает неопределенное значение.