在Angular中,我们可以这样做:
创建一个视图容器,在模板渲染时隐藏它。
使用
template: `<ng-container #c></ng-container>`
或者:
template: `<template #c></template>`
创建一个视图容器,在模板渲染时隐藏它。
使用
ng-container
和html模板的替代方案有什么区别吗?我猜想Angular必须有自己的模板容器,如ng-template
或ng-container
,因为使用原始的html
模板元素可能会破坏非基于浏览器的运行时,例如移动客户端等。
template
HTML标签的等效物是ng-template
而不是ng-container
。并且ng-container
和ng-template
之间也有差异。 - quirimmo