作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
-6ren">
我在每个部分中都留下了一些问题,并且该计数会向用户显示,除非剩下零个问题,在这种情况下我会显示一个复选标记。
<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>
函数 questionsLeft() 被调用了 3 次 - 如何调用一次并重用其结果?我已经尝试过 ng-init 和 {{x = questionsLeft(section); ""}} 欺骗这两个都初始化变量,但当值更改时它不会更新。
最佳答案
section
组件 Controller 内创建一个变量。 questionsLeft
函数更新变量值。例如,您可以在 $onChanges Hook 内执行此操作。附注如果你提供 Controller 代码会更容易说
关于javascript - Angularjs 1.5x : How to call a function only once in a template and reuse the result in multiple places,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38094500/
我是一名优秀的程序员,十分优秀!