简体   繁体   中英

Access Typescript function from Javascript file

I'm curious about how to call a function (in my Typescript file) from my Javascript file.

I know its possible to call between two javascript files.

This is from my function in my javascript file getRowData() is a function in my typescript file.

$table.on('click-row.bs.table', function (e, row, $element) {
    $('.success').removeClass('success');
    $($element).addClass('success');
    getRowData();
}

And this is my Typescript file

export class CustomersScreen extends Screen<void> {
    private customer: CustomerViewModel = new CustomerViewModel();
    private selectedCustomerID: string = "";
    private listOfCustomers: CustomerViewModel[];
    private theTemplate: string = "profile";

    constructor() {
        super("customers", ActiveMenuItem.Customers, FooterActionsSet.None);
    }

    private clearSelection = () => {
        this.customer = new CustomerViewModel();
        this.selectedCustomerID = null;
    };

    public getRowData() {
        alert("something");
    }; 
}

Chrome console just keeps telling me getRowData is not defined.

I think you need to do 2 things :

  • export the function in your JS file (in order to make it available from out)
  • import your JS file into your Typescript

For example in Angular2 using TypeScript, if I need to use Observable in my Component, I have to :

import {Observable} from 'rxjs/Rx'; in my TS File

In rxjs/RX there is an export :

exports.Observable = Observable_1.Observable;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM