Search code examples
htmlangularformsdirectiveangular-ng-if

Angular *ngIf syntax using directive and not a string parameter


I'm reading PluralSight's article on reactive forms to refresh my memory and I can't figure out the syntax shown below.

<div *ngIf courseForm.get('courseName').valid && courseForm.get('courseName').touched>
  Please enter valid course name !
</div>

I can't make it work on my computer, unless I change to the syntax I'm familiar with from before, i.e. a string passed for evaluating the truity like so.

<div *ngIf="courseForm.get('courseName').valid && courseForm.get('courseName').touched">
  Please enter valid course name !
</div>

If it'd be YAF blog, I'd chalk it up to the author's confusion and/or sloppiness but given the reputation of PluralSight, I'm rather prone to question my competence. However, I haven't found any documentation on the new syntax and I'm a bit stumped. Has PluralSight made a booboo?


Solution

  • It should be a mistake, if you look at the ngIf syntax it states,

    A shorthand form of the directive, *ngIf="condition", is generally used, provided as an attribute of the anchor element for the inserted template.