angular - 从服务访问模板引用
问题描述
我想在服务中使用模板引用。例如:
// A component template that I want to use. Can be located anywhere.
<ng-template #announcement_tpl let-data="data">
<div>{{data.title}}</div>
<div>{{data.message}}</div>
</ng-template>
// Called from a callback in an injectable Service, outside the component class.
this.notification_service.template(announcement_tpl)
我刚刚实施了这个解决方案。它有效,但我不确定这是否是一个好习惯。请注意,this.notification_service.template
它不是从组件调用的,而是从服务的回调中调用的,因此不能简单地将模板传递给此方法。我认为理想的解决方案是导入组件并从组件中取出模板(以某种方式),除非当然有更好的方法。
解决方案
推荐阅读
- javascript - javascript 一次捕获多个错误
- liquibase - 执行 DBMS_AQADM 变更集失败 - 原因:liquibase.exception.DatabaseException:ORA-00900:无效的 SQL 语句
- python - NoSuchElementException:消息:没有这样的元素:使用 Selenium 和 Python 抓取前 20 名持有者时无法定位元素错误
- html - 如何仅在屏幕较小时向右浮动,而在屏幕较大时向左浮动?
- amazon-web-services - 带语音搜索的弹性搜索
- python - 如何替换包含完整句子的列的每一行中的多个单词?
- laravel - Nuxt 与 Axios POST 到 Laravel 的 API
- c# - C# Linq 检查上一条记录到当前记录,如果重复则更新金额
- julia - Gurobi求解器中的二进制变量
- ios - 是否可以在 iOS 14+ 中禁用后退导航菜单?