Tips from an Angular Trip - Kata
To continue our journey with Angular, i created a special kata to help dive deeper in the Angular framework. We will be developing an e-commerce application with two pages but full of special tips and tricks.
When finished, the application should look like this: Ng-MarketPlace
Getting Started
- Requirements
- Part one: Angular basics
- Part two: Angular advanced
- Licencing and information
Requirements
A first experience with angular is recommended but not required as the kata will slowly progress from the fundamentals to advanced techniques.
Preparing the machine
- Make sure you have a running internet connection
Install the lastest Node LTS from https://nodejs.org/
Verify node installation using the command lines:
1234node -v# should display 8.11.x or higher1234npm -v# should display 5.6.x or higherOptional: use a code editor (Visual Studio Code is my recommendation)
5) Optional: add the following extensions to visual studio code
Part one: Angular basics
Create a new project (10 min)
- Install Angular CLI1npm install -g @angular/cli
- Create a new project named ng-marketplace (use scss style and mk as prefix)1ng new marketplace --style scss --prefix mk
- Run the application from the marketplace folder1ng serve
- Modify the title from
Welcome to mk!
toWelcome to MarketPlace
Create an order form component (30 min)
- The marketplace has 3 categories described below, create a new component called order-form to display them all.
id | name |
---|---|
1 | Electronics |
2 | Fashion |
3 | Car |
HINT: Use the order-form.component_1.{html|scss} files from kata/components/order-form.
- Every category has it’s own logo like described in the table below, Use font awesome classes to decorate them.
id | name | icon |
---|---|---|
1 | Electronics | fa fa-desktop fa-4x |
2 | Fashion | fa fa-shopping-bag fa-4x |
3 | Car | fa fa-car fa-4x |
HINT: npm install font-awesome.
- The full list of categories is availabe on a remote server. Setup the server then update order-form component to fetch data.
HINT: Use kata/api folder as your source of data.
- Retrieving data from within a component is not a good practise, move the data fetching logic to a dedicated service.
- Run the tests and fix if any is failing.
HINT: Take a look at app.module.ts
- Using the description below, write the following 3 tests for the order-form component
- Should create OrderFormComponent when all modules and dependencies are available.
- Should create 3 radio buttons when total fetched categories is 3
- Should bind second category id to 2 when fetched second category id equals 2
HINT: Use a mocking library like sinon: npm install -D sinon @types/sinon.
Setup purchase form (30 min)
- Create a form to host the category field. Make sure it works by displaying the name of the selected category.
HINT: Use reactive forms module: npm install @angular/forms.
- Every category has its corresponding items, display items everytime a category is selected.
HINT: Fetch items from the remote server (api/items.json).
- Style the displayed items and add an item field to the form.
HINT: Use the html snippet from kata/components/order-form.component_2.html and don’t forget to add images folder to the application.
- Display the selected item details using a child component.
HINT: Use the selected-item component from kata/components/selected-item.component_1.{html|scss} and don’t forget to display the currency properly.
- The selected-item component communicates with order-form to add items to its cart. Display the cart items and total value of the order.
HINT: The cart is on the order-form component. Use the selected-item component from kata/components/selected-item.component_2.html and kata/components/order-form.component_3.html.
Create a order summary component (10 min)
- Create a new component called OrderSummary to display the order summary, it’s should be accessible through /summary route.
HINT: Use HTML and scss provided in kata/components/order-summary.component.{html|scss} and don’t forget, OrderForm page should remain accessible through /marketplace or /.
- OrderSummary should be able to read cart items and display the list of items and total amount of the order
HINT: Communication between two routes can be done using shared services.
Part two: Angular advanced
Route guards (20 min)
- Protect OrderSummary url to prevent user from accessing it before completing the order form
- Categories take a long time to be fetched, display a spinner for the user while waiting on access to order form.
Feature module (20 min)
- Move the OrderSummary component to a feature module called OrderSummary
- Lazy load the OrderSummaryModule
- Build the application in AoT mode then in Prod mode, notice any difference ?
Redux & @NgRx (30 min)
- Setup a store for the application using @NgRx library
- Adapt the ItemsBoardComponent accordingly to use the store
- Install the Redux DevTools extension to test time travel debugging and more features
Licencing and information
Ng-MarketPlace Kata is licensed under a Creative Commons Attribution 3.0 Unported License.
To view a copy of this license, visit [ http://creativecommons.org/licenses/by/3.0/deed.en_US ].
For any questions, contact me on msekni.bilel@gmail.com