and for the complete illustrations project click here to see it on my Behance profile.

Step 2: Development

Here were most guides skip most of the early steps and assume you know everything and then they show you the result to get impressed and nothing more.

But, I am going to try my best to make everyone capable to follow this tutorial even beginners without making the tutorial insanely long and start things off with installing nodejs and the angular CLI which will generate the basic structure and scaffold our Angular app.

install nodejs from the official website from here and open your command line prompt in your OS and install the Angular CLI and typescript globally using the following lines:

npm i -g typescript

npm i -g @angular/cli

after that just run the following command to generate the App using the Angular CLI and don’t forget to add the routing flag which creates a good starting point for the app pagination and routing.

ng new Minimus --routing

once the CLI finishes generating your project files and installs all the dependencies it needs of NPM we are going to start the development server and open our app in the browser using the following command (-o flag is just to open a new browser tab automatically with the correct URL pointing to your app)

ng serve -o

A. Templates And Styling

But before I start, I want to make sure that you get the most of this tutorial so please don’t just copy and paste, read the code and then open your editor and browser side by side and type everything down in your own way because that is the only way you can learn. I typed everything myself to build this app and you should too so you can understand everything thing from start to finish.

Now back to the project where we just completed the basic setup of the app and now we are going to start writing our HTML and CSS. So open up your project in your favorite text editor and let’s dive right in Woohoo!

App Component

we are going to use the root component app.component as our navbar component and we are going to show it and hide it conditionally depending if the user is logged in or not (We will implement Authentication in Part II with Angularfire Lite in the sires).

Here I thought of using some components off the angular material library but I decided to keep the production app as light as possible by avoiding any 3rd party library unless it is really necessary like Angularfire Lite.

First things first open app.component.hml and delete all the boilerplate HTML automatically generated by the CLI and get your HTML to look like something like this:

Bonus Tip (optional):

If you want to use Emmet (an editor plugin) as a faster way of typing HTML you can refer to the plugin cheat sheet I usually refer to.

SVG icons

To get the svg icons and the logo here is a list of gists I created on my Github profile so you can use them (copying and pasting is allowed here) :

— Styling the root component

and it’s time for some CSS to style our navbar, just take a quick look at the CSS below and look at the achieved result and then go ahead and write down your own CSS as it does not have to be exactly the same.

“be inspired don’t copy because everybody is an artist”

CSS explanation:

Layout:

display: grid;

grid-template-columns: auto;

grid-template-rows: 0.5fr auto;

here I am basically using CSS grid layout to divide the page in order to have one small top row for the navbar and a much larger second row to contain our router outlet which is the main content of the page. Think about it like this small diagram:

sidenav

.side-menu__conatiner {

position: fixed;

left: 0;

top: 0 }

places the sidenav container at the top left of the viewport

.side-menu__container::before {...}

used to fade the background with a blue tint when the sidebar slides in

will-change: opacity;

is used to inform the browser ahead of time that the entire background opacity will change so we can achieve a better rendering performance you can read more here.

.slide-menu { transform: translateX(-103%); }

this should pull the side-menu out of the viewport and when we click the hamburger menu we should add a .slide-menu-active class which will reset the transform CSS property and ends up sliding the menu from the left of the viewport:

.slide-menu-active { transform: none; }

mode toggle

a small UI element trick that I want to cover is how I styled is the theme toggle button. Basically I set the appearance CSS property of a standard checkbox input to none just to completely remove any default styling of the input (this is different from display: none which completely hides the element) and then I used two different classes for the toggle button background and the circle to change the color and the position of the circle depending on a boolean variable stored on the component using the built-in ngClass directive in Angular which lets you toggle CSS classes easily.

Home Component

this is the home component where we show the different weather cards of the user’s favorite cities and from there he can click on the add city card which routes him to the add city component to add a new city to his home page.

first, we need to generate this component using the CLI using the following command:

ng g c home

the HTML markup has nothing more than a container and two other components for now but we will dynamically add cards depending on the user favorite cities in the upcoming parts of the tutorial:

Weather Card Component

Here is used the ngSwitch directive to check for the weather conditions and change

and now to some CSS styling of the component:

DarkMode

In the CSS you can notice that I added two classes for most UI elements and the reason for this is we want to add extra CSS classes for the dark theme with -dark suffix so we can toggle them afterward using again the ngClass directive based on the theme toggle button state.

Add Card Component

Here is the add card component I have added a div wrapper that has a conditional dark mode ngClass directive like most of the UI element and I have added a the Angular router routerLink attribute to navigate the user to the add city page when the card is clicked

in terms of CSS again nothing complicated here as the main card uses also gird layout to create 2 rows to evenly space its content. don’t forget also to add the box-shadow property to add some light drop shadow to the card.

Details Component

Here I injected the weather service to retrieve the weather data (more on that later) and set each day name, temperature and weather condition in a separate public variable that I can access in the template to display it:

Obviously there is a lot of filtering and modification done to the data from the weather service so in the next part will move some of the logic to a service.

Please do not forget also to unsubscribe from each subscription in the ngOnDestroy life cycle hook of the component to avoid memory leaks.

The details component has a lot of svgs which made the HTML very long so here is the full component template including the svg icons so I don’t have to include it here.

with the CSS I have followed the dark mode styling for now:

B. Services

we want to decouple the logic of retrieving the API weather data from a specific component and move it to a separate service that we can use throughout the application and again we are going to use the shorthand format to generate a service using the CLI.

Weather service

ng g s weather

this service uses the OpenWeatherMap API to retrieve the weather information and makes some modifications before feeding the data to the components at the end. The API does not inform us about the maximum and minimum temperature value and the free plan also restricts us to access only the 5 days/3 hour forecast data so what I ended up doing is I looped through the 3 hours interval temperatures and extracted an approximate max and min value.

and here is the weather.service.ts code:

as you can see all the functions return a Subject which we will use to broadcast the modified data to any component that subscribes to it. This free weather API sucks and I might create a tutorial on how to transform this ugly REST API to a much nicer GraphQL one so stay tuned.

a quick run-through on what the different service functions do:

— getWeatherState : the current weather state e.g. cloudy - clear…

— getCurrentTemp : the current temperature number

— getMinTemp : the minimum temperature (based on 3 hours interval)

— getMinTemp : the minimum temperature (based on 3 hours interval)

— getCurrentHum : current humidity value (number)

— getCurrentWind : current wind speed (number)

— getForecast : get weather data for the 5 upcoming days

— getCityWeatherByName : return the entire weather data from the API of city name provided as a string

— getCitiesWeathersByNames : returns the entire weather data from the API of the city names provided as an array

UI service

this is small service that has functions that we are going to utilize to share the state of the UI like the theme mode selected (dark or light) application wide.

C. Routing

We have already generated the routing module when we created our app with the CLI but we have to make some modifications to the routing.module.ts to tell Angular what are the different routes (URLs) and their associated components (pages).

📱 Looking To Make This APP Responsive?

using intab.io to test Minimus in iPhone 11 + pixel devices with realtime sync

In part II of this tutorial series, you can find all the media queries I wrote using InTab which is a browser extension to test and autogenerate media queries for various mobile/tablet sizes. It is a faster way to inspect CSS and make a website responsive without switching to your code editor. You can test it live at intab.io if you are interested in a faster CSS workflow.

Conclusion

We made good progress in this very first part of building the Minimus Weather App we got most of the design work from branding to UI and UX decisions, We wrote a lot of HTML & CSS and we made it look beautiful.

Live Demo (V2): https://minimus-weather.web.app

Github Repo: https://github.com/hamedbaatour/Minimus

According to our to-do list here is what we have done so far:

Based on the latest & greatest version of Angular ✅

Modern CSS: Grid Layout & Flex Box ✅

2 Modes : Dark Mode & Light Mode ✅

Beautiful Minimalistic Design ✅

for the next parts of this series will work on the rest of features so be sure not to miss more tutorials like this by subscribing to my personal email list:

you can also follow me on twitter @hamedbaatour where I tweet about some cool front end development stuff.