javascript - 如何更新 ng-template 中的值
问题描述
我有这个模板
<script type="text/ng-template" id="template">
<span class="count-container">
<span >{{count}}</span>
</span>
</script>
我多次包括这个不同的ng-init
像这样
<span ng-include="'template'" ng-init="count=$ctrl.getTotalCount()"></span>
<span ng-include="'template'" ng-init="count=$ctrl.tabs[0].errorCount"></span>
这在第一次加载时工作正常,但是当组件中的值更新时,这些值不会反映在加载模板的位置。我想这是由于它的ng-init
工作原理,因为它在第一次加载时一切都很好。
那么应该使用什么来更新模板中的值呢?
解决方案
您可以使用$watch
:
ng-init="$watch('count=$ctrl.tabs[0].errorCount')"
这只是一个内联解决方案。但是,您应该使用scope.$watch()
.
推荐阅读
- javascript - NodeJS/ExpressJS 不重定向到主页
- javascript - JavaScript:这种特殊字符的替换正确吗?
- typescript - Typescript中显式解包的选项?
- python - 如何使用 pytest 测试 atexit
- javascript - 功能子组件不会在道具更改时重新呈现
- css - 如何使导航栏下拉菜单不扩展纯 CSS 中的导航栏
- php - 无法使用 PHP Simple DOM Parser 访问正确的类/ID
- c - bind() 是否修改 C 中的 sin_port?
- date - Neo4j 过滤结果,其中日期在几个时期的范围内
- java - 使用 JDBC 更新数据库,其中包含一些应忽略的值