Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng-template #71

Open
deepthan opened this issue Jul 27, 2020 · 0 comments
Open

ng-template #71

deepthan opened this issue Jul 27, 2020 · 0 comments

Comments

@deepthan
Copy link
Owner

ng-template

是什么

ng-template是一个模板元素,它里面的内容不会渲染,只有其他代码主动调用读取它,它才会显示出来。

它一般和结构型指令结合使用,如*ngIf, *ngFor, [ngSwitch]或其他自定义指令。

如果只是像下面这样写不会显示出来。

<ng-template>
    <p> 这是一块正经的内容 </p>
</ng-template>

怎么用

<p *ngIf="isCat; else isDog">
    小猫
</p>

<ng-template #isDog> <p>小狗</p> </ng-template>

一般使用场景是有一段html代码,在某个时刻需要使用到会把它包裹在ng-template中。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant