N
N
Nick Smith2018-03-20 19:09:08
JavaScript
Nick Smith, 2018-03-20 19:09:08

How to override method in Prototype in Typescript?

It is necessary to ignore the method in the external lib. How to do it?
I did so, but with AOT compilation it does not bring any effect.

DataTableBodyComponent.prototype.updatePage = () => {}

The class itself looks something like this:
export class DataTableBodyComponent {
    updatePage(direction: string): void {
        //some code...
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nick Smith, 2018-03-21
@Braidner

I hacked like this: I
added a component to the root one and hacked it

<div [hidden]="true">
            <ngx-datatable #dataTable
                           [rows]="[]"
                           [columns]="[]">
            </ngx-datatable>
        </div>

And from the root component I changed the prototype
export class RootComponent implements OnInit{
    @ViewChild('dataTable') dataTable: DatatableComponent;

    ngOnInit(): void {
        Object.getPrototypeOf(this.dataTable.bodyComponent).updatePage = () => {
            console.log("Skip Update Page")
        };
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question