I'm currently in the process of creating a weather application with Angular, where I need to display different icons based on the weather data received. To achieve this functionality, I have developed a function that determines the appropriate icon to display:
icon(icon: any) {
switch (icon) {
case 'rain' :
return '<i class="icon-basecloud"></i><i class="icon-rainy"></i>';
break;
case 'cloudy' :
return '<i class="icon-basecloud"></i><i class="icon-cloud"></i>';
break;
case 'partly-cloudy-day' :
return '<i class="icon-sunny-cloud"></i><i class="icon-sunny-cloud-sunny"></i>';
break;
case 'partly-cloudy-night' :
return '<i class="icon-basecloud"></i><i class="icon-night"></i>';
break;
case 'clear-day' :
return '<i class="icon-day"></i>';
break;
case 'clear-night' :
return '<i class="icon-night"></i>';
break;
default:
return '<i class="icon-basecloud"></i><i class="icon-rainy"></i>';
}
}
However, when attempting to incorporate this function within an innerHtml attribute, the icons did not display as expected.
<div [innerHTML]="icon(temps.currently.icon)"></div>
Upon inspecting the elements, I noticed that the icons were being rendered but not shown on the page. This led me to suspect that there may be an issue related to CSS styling for the icons, as using innerHtml for other types of content, such as images, worked perfectly fine.