У меня есть форма, когда я ввожу значение une, например test, я хотел бы получить значение в модальном режиме, пожалуйста.
1))
2))
Вот мое сообщение об ошибке
error TS2339: Property 'dest' does not exist on type 'TotoResultModalComponent'.
Не могли бы вы помочь мне отобразить значение в модальном окне, пожалуйста?
РОДИТЕЛЬ
toto.component.ts
export class TotoComponent implements OnInit, OnDestroy {
private unsubscribe$ = new Subject<void>();
private svm: string | null = null;
dest: string = '';
constructor(
private service: TotoService,
private router: Router,
private activatedRoute: ActivatedRoute,
private modalService: BsModalService,
private location: Location,
) { }
ngOnInit(): void {
this.svm = this.activatedRoute.snapshot.paramMap.get('svm');
if (!this.svm) {
return;
}
}
ngOnDestroy(): void {
this.unsubscribe$.next();
this.unsubscribe$.complete();
}
openConfirmModal(): void {
const modalRef = this.modalService.show(TotoResultModalComponent, {
...NOT_CLOSABLE_MODAL_OPTIONS,
class: 'modal-dialog-centered modal-lg',
ariaLabelledBy: 'modal-error-title',
initialState: {
},
providers: [
{ provide: TotoService}
]
});
}
}
toto.component.html
<form #formulaire = "ngForm" (ngSubmit) = "formulaire.form.valid">
<div class = "row row-cols-3 pt-3">
<div class = "col text-end">
<label for = "dest" class = "form-label">Name</label>
</div>
<div class = "col-4">
<input
id = "dest"
name = "dest"
type = "text"
class = "form-control"
style = "min-width: 380px"
maxlength = "25"
[(ngModel)] = "dest"
/>
</div>
</div>
<div class = "row row-cols-3 pt-3">
<div class = "col"></div>
<div class = "col text-start">
<button
type = "submit"
class = "btn btn-primary"
(click) = "openConfirmModal()"
style = "background-color: #239CD3;"
[disabled] = "formulaire.form.invalid"
>
Confirm
</button>
</div>
</div>
</form>
РЕБЕНОК
toto-result-modal.component.html
<table class = "table table-hover table-striped spaceLeft" style = "width: 700px">
<tbody>
<tr>
<th style = "width: 60%">Name</th>
<td style = "min-width: 100%">{{ dest}}</td>
</tr>
</tbody>
</table>
toto-result-modal.component.ts
export class TotoResultModalComponent implements OnInit {
private unsubscribe$ = new Subject<void>();
modalService: any;
@Output() closeModal = new EventEmitter<void>();
constructor(
public modal: BsModalRef,
private router: Router,
private location: Location,
private service: TotoService
) { }
ngOnInit(): void {
this.goBack();
}
ngOnDestroy(): void {
this.unsubscribe$.next();
this.unsubscribe$.complete();
}
goBack(): void {
this.modal.hide();
this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => {
this.router.navigate(['/transfers/toto']);
});
}
}





Создайте сервис с Observable dest. Подавайте ему данные в родительском компоненте и подписывайтесь на него в дочернем компоненте. Вы уже предоставляете TotoService, вы можете добавить его туда.
dest$: EventEmitter<string> = new Eventemitter<string>();
dest$.emit(dest);
dest$.subscribe(_ => { ... });
У вас ошибка типа, потому что у TotoResultModalComponent нет свойства dest, но вы вызываете его в html. Просто добавьте свойство.
для отображения внешних данных внутри модального окна вы должны получить BsModalRef и установить свойство dest.
openConfirmModal(): void {
const modalRef = this.modalService.show(TotoResultModalComponent, {
...NOT_CLOSABLE_MODAL_OPTIONS,
class: 'modal-dialog-centered modal-lg',
ariaLabelledBy: 'modal-error-title',
initialState: {
},
providers: [
{ provide: TotoService}
]
});
modalRef.content.dest = this.dest; // add this
}
Вы также можете просто передать его в InitialState:
initialState: {dest: this.dest}
В этом втором разделе модальных документов есть образец.
https://valor-software.com/ngx-bootstrap/#/components/modals#service-component
У меня нет недавнего опыта работы с программным обеспечением valor, но в этом случае оно похоже на другую библиотеку компонентов начальной загрузки.
Пожалуйста, создайте минимальный воспроизводимый пример, показывающий проблему. Вы можете использовать стекблиц для создания MRE. Преимущество MRE в том, что вы можете найти проблему самостоятельно ;) А если вы этого не сделаете, люди могут использовать MRE, чтобы проверить, в чем проблема.