Как запустить API с помощью Modal в Angular 6 - PullRequest
0 голосов
/ 01 февраля 2019

Мне нужна помощь, чтобы узнать, как вызвать API удаления после модального подтверждения в Angular.

onDelete (id: номер) {

this.confirmationDialogService.confirm('Confirm Delete', 'Do you really want to delete this document?')
.then(() => this.employeeService.deleteEmployee(id)) //this is not working
//.catch(() => console.log('User dismissed the dialog (e.g., by using ESC, clicking the cross icon, or clicking outside the dialog)'));

/*if (confirm('Are you sure you want delete this record?') == true) {
  this.employeeService.deleteEmployee(id);
}*/

}

Как вы можете видеть в коде.Мне нужно знать, как я делаю вызов API удаления после нажатия кнопки ОК в модале.

Ответы [ 2 ]

0 голосов
/ 01 февраля 2019

onDelete (id: number) {

this.confirmationDialogService.confirm('Confirm Delete', 'Do you really want to delete this document?')
  .then((confirmed) => {
    this.employeeService.deleteEmployee(id)
    .subscribe(x => {
      this.employeeService.getEmployeeList();
      this.toast.warning("Deleted Sucessfully", 'Employee Register');
    });
  })

}

0 голосов
/ 01 февраля 2019

Попробуйте использовать скобку {} в .then для использования многострочного кода, как показано ниже -

public openConfirmationDialog(id) {
    this.confirmationDialogService.confirm('Please confirm..', 'Do you really want to ... ?')
    .then((confirmed) => {
      this.employeeService.deleteEmployee(id);
      console.log('User confirmed:', confirmed);
    })
    .catch(() => console.log('User dismissed the dialog (e.g., by using ESC, clicking the cross icon, or clicking outside the dialog)'));
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...