javascript - Angularjs 1.5x: How to call a function only once in a template and reuse the result in multiple places -


i have count of questions left in each section , count displayed user unless there 0 left in case display check mark.

<p class="list-group-item-heading">{{section.title}}     <i ng-show="questionsleft(section)==0" class="fa fa-check"></i>     <span ng-show="questionsleft(section)>0" class="label">                             {{questionsleft(section)}}</span> </p> 

the function questionsleft() called 3 times - how can called once , result reused? have tried both ng-init , {{x = questionsleft(section); ""}} trick both of initialize variable not update when value changes.

  1. create variable inside section component controller.
  2. put variable instead of function inside template.
  3. update variable value each time number of questions changed questionsleft function. can inside $onchanges hook, instance.

p.s. easier if provide controller code


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -