Skip to content

Tech Leads Programming Class Week 3

Posted in Personal

Continuing from where we left off in week 2, we want to start with setting up our Angular project. Angular is a frontend framework with many features we hope to explore gradually in this week’s discussion and next week.

Check the Week 2 Class to learn more about what we discussed.

The repository for our Week 2 Class is available at https://github.com/seanmavley/techleadsclass

This week’s class will let us introduce the pages we built in Week 2 into our Angular. Our choice of Angular is based on the many features it offers us. You can read more about Angular on the official pages.

Install Angular CLI

For easy development with Angular, there is the command line tool available. This command line tool comes with options to help make our development process faster and easier at the same time.

You can read about the Angular CLI: https://github.com/angular/angular-cli

To install the CLI of Angular globally on your computer, enter the command below in your Terminal (or Command Prompt)

The -goption tells NPM to install this package globally, on our computer, therefore wherever we are in the terminal, we could simply run the command from this package and use it. We’ll see that in action pretty soon.

A Thing or Two with Git

We wanna use our same Project folder to hold the new changes we want to do, related to installing angular etc. Since we don’t want the files to mix up and whatnot, let us create a new git branch to hold our layout designs from last week, and this week’s angular changes also in a new one.

A Git branch allows us to have different stages of our application under a branch name, without mixing them up.

Let’s see in action and discuss them line by line

  1. We change directory into our Home Folder
  2. From there, we go into the Project folder
  3. We then list the git branches available with the -l option
    1. This should basically give us *master result only
  4. git branch AppLayout creates a new branch with name, AppLayout
  5. Listing available branches now gets us, *master AppLayout
  6. We then checkout, or switch to the AppLayout branch
  7. We push the newly created branch to the online Github
  8. We switch back to the master branch

The next step is to create our new Angular project. First, let us delete everything in the folder and initialize a new angular project.

The first two commands, we’ve seen used above.

The rm -r * is saying, we want everything within the current folder we’re in, that’s the Developments/Projectfolder, should be deleted. The -rflag is saying, delete even folders and recursively delete any folders within folders.

Remember we installed the Angular CLI above? After installation, we got the command, ngng is the Angular CLI command for everything related to our Angular project.

As we move on, we shall see how the command gives us more options to do more easily.

The ng new AngularApp --directory ./ --skip-git in English will be something like this:

“Create a new Angular Project, call it AngularApp, put it in the same directory this command was run from, and don’t initialize a Git project”

We don’t wanna initialize a Git project because we already have a git project going for us.

You might be wondering, ‘Ah, but we deleted everything from the Project Folder’.

Well, not everything. The rm command we used doesn’t touch hidden folders. Hidden folders begin with a ., for example, any git project will have a folder as .git.

We’ve installed our Angular project, and we should have a folder structure like this:

Our Angular Folder Structure

Let’s commit our changes so far into Git, so we can move onto the next steps

Last but not least, let us view the current state of the project in the browser.

We use the ng command line tool to our advantage again. The servemeans it should run the project and the -o indicates it should open it in the browser for us.

Our Angular Page running

A Few Configurations

Since we wanna use Bootstrap for our Angular Project as well, let us tell angular to include the Bootstrap files.

First, we need to install the bootstrap and its related dependencies. We did that when we were setting up for the design layout in Week 2. We only need this command run in the Project folder.

npm install bootstrap@4.0.0-beta popper.js jquery --save

After the installation is done, please find the file, .angular-cli.json which is within the Project folder, and let’s make these changes to it.

The highlighted sections above are the changes we will add in the .angular-cli.json file.

Since we’ve enabled Service Workers for our Angular project, "serviceWorker": true,, we need to run this command to have the service workers dependency installed:

npm install --save-dev @angular/service-worker

Done!

HomePage & Other Pages

Let us generate the individual pages in our Angular app.

One of the main approaches in Angular is having what is referred to as, Components. We will be creating a component for each and every page. Therefore, our Homepage, About, Dashboard and Login-Register will each be a component.

Having components is a beautiful way of separating the logic of each page from the other. Plus, we can apply specific CSS styles to each Component as and when we need, without having to affect other components.

To generate a component, let’s use the ng command, yet again.

ng generate component [name]

When done with the above commands, create a new file, app.routing.ts in the /src/app folder, and put in this:

For the next steps, see the video below:

In all, here’s what we ended up with.

Next week’s class will take us through setting up our means of communicating with a back-end.