29

I was trying to see 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()
{
    ...
}

The function is called htmlgeneration. Essentially, what I want to do is dynamically append HTML inside the li element while using AngularJS.

1
  • While calling a function from HTmL like @SomeKittens said , Your function will be called more than once . Why ? Answer is Here . So be careful when calling function from HTML . It may slowdown the loading of your page . Commented Feb 7, 2019 at 8:45

2 Answers 2

62

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>
Sign up to request clarification or add additional context in comments.

2 Comments

is there a way to do it using parameters?
@Serge Yes, pass the parameters to the function as normal.
0

I guess my problem was related to conflicts with Django tags. This post was helpful.

What worked for me was a simple solution involving using ng-bind and changing the code to something like this:

<ul class="ui-listview ui-radiobutton" ng-repeat="meter in meters">
  <li class="ui-divider" ng-bind="htmlgeneration(meter.DESCRIPTION)">
  </li>
</ul>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.