I am trying to upload an image pictureA
or image pictureB
My first solution is this:
<img *ngIf="my_picture" src="{{my_picture}}" width="180" height="80" >
<img *ngIf="default_picture && !my_picture" src="{{default_picture}}">
But I would like to use if
- else
as on the API Reference:
<div *ngIf="condition; else elseBlock">...</div>
<ng-template #elseBlock>...</ng-template>
So, I'm trying to do it like this:
<div *ngIf="my_picture; else elseBlock">
<img src="{{my_picture}}" >
</div>
<ng-template #elseBlock>
<img src="{{default_picture}}" >
</ng-template>
But I get a big trace of the exception stack:
zone.js:388 Unhandled Promise rejection: Template parse errors:
Can't bind to 'ngIfElse' since it isn't a known property of 'div'. ("
-->
<div [ERROR ->]*ngIf="my_picture; else elseBlock">
<img src="{{my_picture}}"): UserComponent@15:13
Property binding ngIfElse not used by any directive on an embedded template. Make sure that the property name is spelled correctly and
all directives are listed in "@ NgModule.declarations". ("->
[ERROR ->]<div *ngIf="my_picture; else elseBlock">
<img src="{{my_picture}}" width="180" height="8"): UserComponent@15:8
'ng-template' is not a known element
How can I implement a simple block if
- else
?
source
share