Angular的ngIf和NgIf有何区别

时间:2022-07-23
本文章向大家介绍Angular的ngIf和NgIf有何区别,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

在Angular官方文档里,可以看到ngIf和NgIf这两种拼写混杂使用。NgIf refers to the directive class; ngIf refers to the directive’s attribute name.

A directive class is spelled in UpperCamelCase (NgIf). A directive’s attribute name is spelled in lowerCamelCase (ngIf). The guide refers to the directive class when talking about its properties and what the directive does.

The guide refers to the attribute name when describing how you apply the directive to an element in the HTML template. 例如:

运行时生成的原生html代码:

ngIf里包裹的input field:

<label>name:
        <input [(ngModel)]="hero.name" placeholder="name"/>
</label>

[(ngModel)]="hero.name"展开成源代码:

ng-reflect-model=”Dr Nice“