Во время инициализации на сервер не отправляется ни один запрос и не отображается ошибка - PullRequest
0 голосов
/ 06 мая 2020

Я пытаюсь подключиться к бэкэнду, используя angular datatable, но во время инициализации не отправляется запрос на сервер и не отображается ошибка. Вот код для передней части

class Religion {
  id:number;
  name: string;
}
class DataTablesResponse {
  data: any[];
  draw: number;
  recordsFiltered: number;
  recordsTotal: number;
  error:string;
}

@Component({
  selector: 'app-faith',
  templateUrl: './faith.component.html',
  styleUrls: ['./faith.component.scss']
})
export class FaithComponent implements OnInit {
  //Datatables settings
  dtOptions: DataTables.Settings = {}
  //DATA LISTS
  religionList: Religion[];
  constructor(public dialog: MatDialog, public faithService:FaithService, public http: HttpClient, private toastr: ToastrService) { 
  }
  loadReligion(){
    const that = this;
    this.dtOptions = {
      pagingType: 'full_numbers',
      pageLength: 100,
      serverSide: true,
      processing: true,
      ajax: (dataTablesParameters: any, callback) => {
        that.http.post<DataTablesResponse>(environment.rootUrl + 'religion-list/', dataTablesParameters, {}).subscribe(resp => {
          console.log(resp);
          that.religionList = resp.data
          callback({
            recordsTotal: resp.recordsTotal,
            recordsFiltered: resp.recordsFiltered,
            data: []
          });
        });
      },
      columns: [{data:'id'},{ data: 'name' }]
    }
  }
  ngOnInit(){
    this.loadReligion(); 
  }

Я очень признателен за любой вклад

...