Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  128] [ 1]  / answers: 1 / hits: 42644  / 8 Years ago, mon, may 16, 2016, 12:00:00

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').


More From » html

 Answers
24

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


[#62145] Saturday, May 14, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eanskylerg

Total Points: 524
Total Questions: 107
Total Answers: 100

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
;