繁体   English   中英

如何更新 ng-template 中的值

[英]How to update values in 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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM