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. 例如:

Angular的ngIf和NgIf有何区别_第1张图片

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

Angular的ngIf和NgIf有何区别_第2张图片

ngIf里包裹的input field:

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

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

ng-reflect-model=”Dr Nice“

Angular的ngIf和NgIf有何区别_第3张图片

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

你可能感兴趣的:(TypeScript,Angular)