I am writing lot of ngIf statements, rendering an html form, when a product description search contains a keyword.
How do I convert this to ngSwitch?
Current ngIf statement
<app-store *ngIf="message?.productDescription.includes('Cars')">
<app-carform></app-carform>
</app-store>
<app-store *ngIf="message?.productDescription.includes('Reading')">
<app-bookform></app-bookform>
</app-store>
<app-store *ngIf="message?.productDescription.includes('Furniture')">
<app-homefurnitureform></app-homefurnitureform>
</app-store>
Example ngSwitch:
I am reading Sample Ngswitch statements, but don't know how to convert the above, if its even possible in angular.
<div [ngSwitch]="productDescription">
<p *ngSwitchCase="'Cars'"><app-carform></app-carform></p>
<p *ngSwitchCase="'Reading'"><app-bookform></app-bookform></p>
<p *ngSwitchCase="'Furniture'"><app-homefurnitureform></app-homefurnitureform></p>
</span>
message?.productDescription.includes('Cars')into a method in your component and then invoke that method by passing in a parameter. Not sure if that would work for you.