Issue
So most of us probably know the "store the conditional variable in a variable"-hack with *ngIf="assertType(item) as renamedItem"
to assign a type to a variable
For me it was always pretty useful as in this example
<ng-template
gridCellTemplate
let-item
>
<ng-container *ngIf="assertType(item) as typedItem">
...
</ng-container>
</ng-template>
and
public assertType(item: any): ITEM_TYPE {
return item;
}
Is there a way to achieve this with the new controlflow syntax @if () {...}
?
Solution
This should solve your issue:
<ng-template
gridCellTemplate
let-item
>
@if (assertType(item); as typedItem) {
<ng-container>
...
</ng-container>
}
</ng-template>
Answered By - Oscar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.