๐ป Lab 2 - Generate an Angular app
May 31, 2023 ยท View on GitHub
โฐ Estimated time: 15-20 minutes
In this lab we'll generate our first Angular application within the new monorepo.
๐ Learning outcomes:
- Get familiar with generating new apps within your workspace using the Nx CLI
๐ฒ After this workshop, your app should look similar to this:
App Screenshot
File structure
๐๏ธโโ๏ธ Steps:
- Make sure you can run Nx commands:
- try out
nx --versionand see if it outputs a version number - install the CLI globally:
npm i -g nx - if you don't want to install it globally, use
npx nxinstead ofnxin all the commands below
- try out
Please make sure you are using the latest version of Nx (14.5+)
-
Run
nx listto see which plugins you have installed and which are available
-
Add the Angular plugin:
@nx/angular
-
Let's also add Angular Material so we can use some of their components:
@angular/material @angular/cdk
-
Use the
@nx/angularplugin to generate an Angular app calledstorein your new workspaceโ ๏ธImportant: Make sure you enable routing when asked!
๐ณ Hint
-
Create a new
index.tsfile in the folderapps/store/src/fake-apiin your app, it returns an array of some games (you can copy the code from here)โณReminder: When you are given example files to copy, the folder they're in hints to the folder and filename you can place them in when you do the copying.
-
Add some basic styling to your new component and display the games from the Fake API (to not spend too much time on this, you can copy it from here .html / .css / .ts - and replace the full contents of the files)
- You can get the example game images from here
โ ๏ธ Make sure you put them in the correct folder
- You can get the example game images from here
-
Add the Material Card Module to
app.module.ts:import { MatCardModule } from '@angular/material/card';Don't forget to add it to the imports section as well.
-
Serve the app:
nx serve store
-
See your app live at http://localhost:4200/
โ ๏ธ In a company context you might need to define a hostname nx serve store --host=my.host.name
- Inspect what changed from the last time you committed, then commit your changes
Now we're starting to see some content! But there are some styles missing: the Angular Material theme! We'll look at how to add it in the next workshop!
The ratings also don't look that good - we'll fix those in Lab 5.
๐If you get stuck, check out the solution