Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call an angular function inside html

I was seeing if there is a way to call a function I designed inside the scope.

<ul class="ui-listview ui-radiobutton" ng-repeat="meter in meters">             <li class = "ui-divider">                 {{meter.DESCRIPTION}}                 {{htmlgeneration}}             </li> </ul>  $scope.htmlgeneration = function() {  blah blah } 

The function is called htmlgeneration. Essentially what I want to do is dynamically append html inside the LI element while using angular.

like image 650
Derek Parker Avatar asked Mar 28 '14 21:03

Derek Parker


People also ask

How do you call a function in HTML?

To invoke this function in the html document, we have to create a simple button and using the onclick event attribute (which is an event handler) along with it, we can call the function by clicking on the button. In the above-given program, we have created a simple HTML document.

How do you call a function in ngIf?

Try *ngIf="condition && yourfunction()" . Your function must return true to the if evaluate to true, but it will only be executed if your condition is true, since an and operator will stop on first false.

How do you call a function in AngularJS?

You can call your angularJS function from javascript or jquery with the help of angular. element().


1 Answers

Yep, just add parenthesis (calling the function). Make sure the function is in scope and actually returns something.

<ul class="ui-listview ui-radiobutton" ng-repeat="meter in meters">   <li class = "ui-divider">     {{ meter.DESCRIPTION }}     {{ htmlgeneration() }}   </li> </ul> 
like image 137
SomeKittens Avatar answered Oct 04 '22 06:10

SomeKittens