Reputation:
I have two components that must be renderized by a expression:
HTML:
<div *ngFor="let avaliacao of avaliacoes" [ngSwitch]="escolha_layout_avaliacao">
<app-avaliacao-produto-modelo-emoji *ngSwitchCase="emoji" [avaliacao]="avaliacao"></app-avaliacao-produto-modelo-emoji>
<app-avaliacao-produto *ngSwitchDefault [avaliacao]="avaliacao"></app-avaliacao-produto>
</div>
TS:
escolha_layout_avaliacao: string
ngOnInit() {
this.buscaDadosLayout()
}
buscaDadosLayout(){
this.escolha_layout_avaliacao = "emoji"
}
But the *ngSwitch
is only rendering the default option, ignoring the condition that have the value "emoji".
If i put in my html: {{escolha_layout_avaliacao}}
i have the value "emoji", but the *ngSwitchCase
only render the default case.
Upvotes: 0
Views: 161
Reputation: 1698
The argument you provide to *ngSwitchCase will be evaluated on your component's scope. So if you pass emoji, it will compare with the value of emoji variable which does not exist in your case.
Try it with string literals: *ngSwitchCase="'emoji'"
Upvotes: 3