gpt4 book ai didi

Angular2 ng-template 文档和使用

转载 作者:太空狗 更新时间:2023-10-29 17:16:52 25 4
gpt4 key购买 nike

我将我的项目更新到最新的 angular2 4.0.0-rc.5,并且在构建它时会发出很多这样的警告:

Template parse warnings:
The <template> element is deprecated. Use <ng-template> instead ("_newGroupReward.group.description}}

我的问题是 - 什么是它,在哪里可以找到有关它的信息以及如何使用它?我一直在谷歌搜索,但我能找到的唯一文档是关于稳定的 2.4.x 版本 ( official docs )。

最好的问候

最佳答案

ngTemplate 是模板的替代品,当示例模板应该注入(inject) DOM 时使用它。

下面的例子是用ngIf else来说明的,

<ng-template #loading>Failed to do something wrong...</ng-template>
<div *ngIf="userObservable;else loading;">
Aravind is here
</div>

当我使用加载时,angular 调用名为 loading 的 TemplateRef,由 #loading 表示,相应的模板在 div 中被替换。

LIVE DEMO

Documentation link

关于Angular2 ng-template 文档和使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42927257/

25 4 0