Calling a function in a typescript file from HTML.

34,257

There is feature provided by angular is events binding by using you are able to call function whihc is exist in your ts file also you can use interpolation syntax of angular to call function like this : -

<button (click)='getConfigurations("parameter")'>Button Click</button>

or something like this

{{getConfigurations('parameter')}}  

for more info related to event binding in angular2 see here

working example Working Plunker

Share:
34,257
Roka545
Author by

Roka545

Updated on July 09, 2022

Comments

  • Roka545
    Roka545 almost 2 years

    I'm new to HTML and Angular 2. I'm currently trying to figure out how to call a function that's inside a Typescript file from an HTML file.

    Stripped down, the Typescript file (home.ts) function looks like this:

    getConfigurations(sensorName: string) {
        console.log('Home:getConfigurations entered...');
    
        return 'sensor1';
    }
    

    In my HTML file (home.html), I would like to call 'getConfigurations' with a string parameter (right now 'getConfigurations()' returns 'sensor1' since I'm still testing things out). So, in HTML, how do I go about calling my getConfigurations method with a parameter (for simplicity - how can I call the method inside a simple div panel)? (I already have the value I want to pass in a variable called 'selectedSensor').