Encountering the ObjectUnsubscribedErrorImpl while utilizing angular datatable with angular version 7

I am encountering an issue when trying to display a DataTable in a modal window. Initially, everything works as expected and I can see the screen perfectly. However, after closing the modal window and opening it again, the DataTable no longer shows the search box or pagination options.

Can someone assist me in resolving this problem?

Expected Result:

Actual Result:

Error:

my.component.ts

    @ViewChild(DataTableDirective)
    dtElement: DataTableDirective;

    dtOptions: DataTables.Settings = {};

    // We use this trigger because fetching the list of items can be time-consuming,
    // so we ensure data is fetched before rendering
    dtTrigger: Subject<any> = new Subject();

    ngOnInit() {
    this.service.getQueryResult(this.saveIteratorParams).subscribe( data => {
          if (data.success !== false) {
            this.queryViewResultL = data.payload;

            this.tableDataList = data.payload.molResults;

            if (this.tableDataList !== null || this.tableDataList !== undefined) {
              this.theadData = Object.keys(this.tableDataList[0]);

              // Calling the DT trigger to manually render the table
              this.dtOptions = {
                pagingType: 'full_numbers',
                pageLength: 10
              };

              this.dtTrigger.next();
            }
    }

    ngAfterViewInit(): void {
        this.dtTrigger.next();
        // console.log('ngAfterViewInit');
      }

      rerender(): void {
        this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
          // Destroy the table first
          dtInstance.destroy();
          // Call the dtTrigger to rerender again
          this.dtTrigger.next();
          // if (this.dtTrigger.observers) { this.dtTrigger.next(); }
        });
      }

      ngOnDestroy(): void {
        // Do not forget to unsubscribe from the event
        this.dtTrigger.unsubscribe();
        console.log('this.dtTrigger.unsubscribe()', this.dtTrigger);

      }

Answer №1

It's uncertain what specific issue you're facing. I encountered a similar error during my project work. This type of error typically indicates that the subscriber or main method has been altered by another piece of code, causing it to unsubscribe. You can diagnose this using developer tools. On the right side, look for the watch feature. Enter the expression name there, such as this.service.getQueryResult(this.saveIteratorParams). Based on this code snippet, it seems like the destroy function may be causing the interruption.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting the error message "TypeError: Cannot read property 'name' of undefined" when working with data binding in Angular 4

I am brand new to Angular and I have been working on creating a custom Component. Specifically, I am trying to display a list of Courses (objects) which consist of two properties: id and name. So far, this logic is functioning properly. However, when attem ...

What is the best way to obtain clear HTTP request data in a component?

My service retrieves JSON data from the backend: constructor(private http: Http) { }; getUsers(): Observable<any> { return this.http.get('http://127.0.0.1:8000/app_todo2/users_list'); }; In the component, this data is processed: ng ...

After installing the latest version of Node.js, the stability of the Ionic environment

After updating nodejs from v8.1 to v12, my ionic environment is experiencing instability. Any suggestions on what needs to be updated? [abc]$ ionic cordova emulate android When running ng run app:ionic-cordova-build --platform=android, an unhandled exce ...

Using Typescript: Defining a property's type based on the value of another property in the same object

I'm dealing with a TypeScript interface that consists of two properties (type:string and args:object). The contents of the args property may vary based on the value of the type. I'm looking for the correct type definition to specify for the args ...

Discover the data type without using the extends keyword within an interface in Typescript

I'm struggling with making my code declarative enough. I want to infer a type inside an interface scope and then use that same type as an argument for a method within the interface. Here is a simple example: interface Prop { x: infer U, // ^^ ...

Collaborate on Typescript Interfaces within a Firebase development environment

I've been developing a Firebase project using Angular for the frontend, and incorporating the @angular/fire library. Within this project, I have created multiple interfaces that utilize firebase and firestore types. For example: export interface ...

Pagination in Angular 2

My current implementation involves using ngx pagination. I have successfully changed the navigation list by passing (pageChange)="p = $event". However, I now want to send the p value to a function like (pageChange)="pageChange(p)" and then set p = $event w ...

Angular SwiperJs integration: smoothly move three slides with a single click

I am currently utilizing the SwiperJs library in conjunction with Angular. I am interested in adding a feature where clicking will navigate to the next (or previous) 3 slides instead of just 1 slide. The regular arrows function correctly, with this code ...

The datatable does not adjust to changes in page size

My jsfiddle example showcases different card boxes, and I am currently focusing on making the 'Table 1' box responsive. However, I have encountered an issue: Check out my jsfiddle example here code If you open the jsfiddle with a large enough ...

What is the best way to set the minDate and maxDate of the NgbDatePicker in the main component so that the settings can be applied

Within my Angular 4 project, I have integrated Ng-bootstrap (v1.1.0) which includes multiple date pickers across different modules. I am looking to enforce a global maxDate configuration for all these instances. Below is an overview of my folder structure: ...

having difficulty sending a post request with Angular

Submitting form data via HTTP post will look like this: saveDataFile(mutlidata,id,value): Observable<Response> { var _url = 'http://xxxx.xxx.xxx'; var saveDataURL = _url + '/' + id; var _this = this; ...

Executing an Observable function in Angular Typescript a single time

Within my Angular application, there exists a service responsible for retrieving data from a server. load.service.ts: load = new Observable(observer => { console.log('load function called'); // asynchronous tasks with time delay obser ...

Ensuring the Presence of a Legitimate Instance in NestJS

I have been working on validating my request with the Product entity DTO. Everything seems to be in order, except for the 'From' and 'To' fields. The validation works correctly for the Customer and Type fields, but when incorrect data i ...

Loading an Ionic module lazily within a children array is a smart way to

Within my Ionic application, I have structured a List Page Module and a Subdir Page Module nested under the main Page module. The folder structure looks like this ---> list/subdir. https://i.sstatic.net/XGrnU.png Dilemma: Whenever I navigate to localh ...

The response you have received is delayed by one response

I seem to be facing an issue with my Node.js server where the response I receive is always delayed by one. The response I expect to get at the time of pressing the upload button is always received one step later. After starting the Node server, the initia ...

The function getServerSideProps does not return any value

I'm a beginner with Next.js and I'm currently using getServerSideProps to retrieve an array of objects. This array is fetched from a backend API by utilizing the page parameters as explained in the dynamic routes documentation: https://nextjs.org ...

Module for importing text without verifying types using wildcards

Here is a unique module definition using the wildcard character: declare module 'custom!*' { const data: string; export default data; } Check out how it's imported: import * as myData from 'custom!./myCustomData.txt'; B ...

Issue encountered during the installation of angular2 cli

I'm currently setting up angular2 on my Linux machine, using the following command: sudo npm install -g @angular/cli After successfully installing it, I proceed with creating a new app by typing: ng new mynewapp However, when doing so, I encounter ...

The Core.js file seems to be missing, but it can be found in the node modules directory. The Meteor client is functioning properly, but there seems to be

I encountered an issue while trying to import the meteor-client.js file. The problem arose when loading ecmascript-runtime-client, which prompted me with an error stating that the core-js npm package could not be found in my node_modules directory. Even af ...

Looking for a way to make certain pages in Vue3 accessible without authentication using KeyCloak-js

Currently, I am integrating keycloak-js adapter into a Vue 3 Application. The challenge I am facing is with the system's public pages, which prevent me from calling Keycloak immediately. Even though I have set up a button to trigger the login page, th ...