Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
20
rated 0 times [  23] [ 3]  / answers: 1 / hits: 25647  / 8 Years ago, thu, july 14, 2016, 12:00:00

I know how to call a TypeScript when clicking a button, but how do you call a function without that type of event? I would like to call a function when I have an array called chartData populated. This is what I have:



        <div *ngIf=chartData.length>
chartMethod();
</div>


But instead of chartMethod() being called, it just prints 'chartMethod()' on the html page.



I've also tried:



            <script> 
chartTest();
</script>


but the function was still not called.


More From » html

 Answers
3

It happens because this chartTest() is incapsulated by Angular and is not accessible outside Angular.
But inside angular you can, you just need to:



<div *ngIf=chartData.length>
{{chartMethod()}}
</div>


But it will add an undefined in html so just test



<div *ngIf=chartData.length>
{{chartMethod() ? chartMethod() : }}
</div>


But I don't think it's html resposibillity call any method, it needs to be done by the component itself in typescript.


[#61365] Wednesday, July 13, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
minab

Total Points: 701
Total Questions: 104
Total Answers: 91

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;