I am trying to use if else with angular to filter the images from the controller. I am trying to show the image with my list if it exists and if not it show the placeholder image.I am new to angular can someone please guide.
I have tried some online solutions to use with it like
<div *ngIf="{{item.icon}}; else templateName">
<img ng-src = "{{item.icon}}" />
</div>
<ng-template #templateName>
<img ng-src = "{{item.placeholderImage}}" />
</ng-template>
I have created this component which I am trying to call in my index file. I am also not able to display the dates which was working before I transferred it in the component. I think there is something wrong with the commas.
{{date | date:"EEE MMM dd yyyy"}}
module('cListApp').
component('itemsList', {
template:<ul>
<li class="list-body-container" ng-repeat="item in $ctrl.items">
<div class="profileImage">
</div>
<div class="list-body-left">
<div class="li-title"><h2>{{item.name}}</h2><h4>Title3</h4></div>
<div class="li-body"><p>{{item.snippet}}</p></div>
<div class="li-date">
<div id="calendar">
<div id="c-top">
<span id="l1"></span>
<span id="l2"></span>
</div>
<div id="c-mark"></div>
</div>
{{date | date:"EEE MMM dd yyyy"}}
</div>
</div>
<div class="list-body-right">
</div>
</li>
</ul>,
controller: function cListController() {
this.items = [
{
name: 'Nexus S',
snippet: 'Fast just got faster with Nexus S.',
icon: 'https://picsum.photos/100/100/?image=491'
}, {
name: 'Motorola XOOM™ with Wi-Fi',
snippet: 'The Next, Next Generation tablet.'
},
],
this.placeholderImage = 'https://picsum.photos/100/100/?blur',
this.date = new Date();
}
});```
[src]=“item.icon”? To set src attribute to a dynamic value?ng-srcis angularjs directive.*ngIfis angular directive. Looks like you're doing angularjs? Which should of beenng-if?