List all our challenges for this Angular 2 course
No Challenge here but some commands to type in a terminal.
- Install NVM (https://github.com/creationix/nvm#install-script)
- Install a Node Version through NVM
nvm install 7
nvm alias default 7
- Install (
angular-cli
)[https://cli.angular.io] `npm install -g @angular/cli - Create a working directory
mkdir my/working/directory
cd my/working/directory
- Boostrap an angular cli application
ng new myProjectName
cd myProjectName
# Run the application through http://localhost:4200
ng serve
You can also clone this project and switch between branches
Take a look at https://yarnpkg.com to get a faster Node Package Manager
Main idea: use ng generate and be familiar with basic component
- Create a component called
header
ng generate component header
- Add the selector element
<app-header></<app-header>
into the main HTMLapp.component.html
- Play with template to see what's going on
a. Add link to welcome & products page
b. Add code between
<app-header>
and</<app-header>
c. be genious :D
Working based on 03 source code
**Main idea: create a product list view by using ngIf & ngFor directives
- Create a component called
product-list
- Add the selector element into the
app.component.html
- Work on the product-list component class a. Add an initial collection of product
products = [
{
"id": 1,
"productName": "Leaf Rake",
"productCode": "GDN-0011",
"releaseDate": "March 19, 2016",
"description": "Leaf rake with 48-inch wooden handle.",
"price": 19.95,
"starRating": 3.2,
"imageUrl": "http://openclipart.org/image/300px/svg_to_png/26215/Anonymous_Leaf_Rake.png"
},
{
"id": 2,
"productName": "Garden Cart",
"productCode": "GDN-0023",
"releaseDate": "March 18, 2016",
"description": "15 gallon capacity rolling garden cart",
"price": 32.99,
"starRating": 4.2,
"imageUrl": "http://openclipart.org/image/300px/svg_to_png/58471/garden_cart.png"
},
{
"id": 5,
"productName": "Hammer",
"productCode": "TBX-0048",
"releaseDate": "May 21, 2016",
"description": "Curved claw steel hammer",
"price": 8.9,
"starRating": 4.8,
"imageUrl": "http://openclipart.org/image/300px/svg_to_png/73/rejon_Hammer.png"
},
{
"id": 8,
"productName": "Saw",
"productCode": "TBX-0022",
"releaseDate": "May 15, 2016",
"description": "15-inch steel blade hand saw",
"price": 11.55,
"starRating": 3.7,
"imageUrl": "http://openclipart.org/image/300px/svg_to_png/27070/egore911_saw.png"
},
{
"id": 10,
"productName": "Video Game Controller",
"productCode": "GMG-0042",
"releaseDate": "October 15, 2015",
"description": "Standard two-button video game controller",
"price": 35.95,
"starRating": 4.6,
"imageUrl": "http://openclipart.org/image/300px/svg_to_png/120337/xbox-controller_01.png"
}
]
- Work on the product-list component template
a. Add a table to display product (display image url as text)
b. Use
*ngIf
directive to show the table if there is no product in the array c. Use*ngFor
directive on<tr>
element to repeat this element as many times as products in the array d. Add a button to show/hide all images on the page - OPTIONAL: Add multiple images per product with a caroussel
Working based on 04 source code
- Display image as
<img src...
into the table with a property binding toproduct.imageUrl
- Insert a button at the top of the table and set an event binding to display and hide all images
The text should be adapted to the current stage:
Show the images
orHide the images
- Develop the filter two-way binding (input text <=> display) (use banana in the box
[()]
)
Working based on 05 source code
- Develop the
productFilter
pipe and use it into the product-list view. - Use Component lifecycle to
console.log
a message into theonInit
event - Add specific style for the product-list component
- Add filter to product information (eg: currency, uppercase, etc.)
Working based on 06 source code
- Create a
starComponent
which display the rating with stars - Use this component into our
productListComponent
and place it next to existingproduct.starRating
- Set-up
rating
input intostarComponent
- Set-up
ratingClicked
output intostarComponent
- Listen
ratingClicked
event fromProductListComponent
Working based on 07 source code
- Create a new angular service called
ProductService
$ ng generate service shared/models/product
- Ensure that it will be declared at our appModule level
- Move the IProduct interface and the products array from our
productListComponent
to this new service - Write a public
getProducts
method to access to this products array - [OPTIONAL]: Write a public
getObservableProducts
which return an Observable
Working based on 08 source code
- Import the
HttpModule
into theAppModule
(if not already done)- Install the
@angular/http
module - Import the
HttpModule
into ourAppModule
- Install the
- Inject
Http
into ourProductService
- Update the
getProducts()
method to make aget
call to our API Servicehttp://localhost:3000/products
- Use
RxJS
methods:map
to convert the string result into a JSON Objectdo
toconsole.log
the JSON Objectcatch
to attach a method to handle errors
- Change into
ProductListComponent
the way we retrieve the data from ourProductService
Working based on 09 source code
- Create a simple
ProductDetailComponent
and aWelcomeComponent
with a basic template - Import the
RouterModule
into theAppModule
(if not already there)- Install the
@angular/router
module - Import the
RouterModule
into ourAppModule
- Use the
RouterModule.forRoot([])
syntax to describe the application's routes (Note that `RouterModule.forChild([]) is used in angular sub-module of our application)
- Install the
- Add the
<router-outlet></router-outlet>
instead of ourapp-product-list
directive into ourAppRootComponent
- Add a menu to navigate through Home and Product List pages using the directive
[routerLink]
directive - Add to the
ProductDetailComponent
two link:
- One to go back to
/products
route - an other to go to the next product detail page
FROM THIS POINT IT NEEDS TO BE UPDATED!
Working based on 10 source code
- Read
id
parameter from url inProductDetailComponent
usingActivatedRoute
- Develop a method
getProductById(id:number)
in ourProductService
- Develop the
ProductDetailComponent
to display real product detail information by retrieving the product from ourProductService
- Implement a Guard to check the validity of given
id
Working based on 11 source code
- Create a new component called
ProductEditComponent
with a basic edit form of a product - Use
template driven form
- Use
[(ngModel)]
on each input to create a two-way binding - Add the hash operator to retrieve the current
ngModel
state (eg.#nameInput
) - Display an error box below based on
nameInput.valid
- Implement a
(ngSubmit)
method to execute a function when user submit
- Use
- Use
model driven form
- Update the form to use
[ngFormModel]=formName
on the<form>
DOM node - Changes all
[(ngModel)]
into angControl="inputName"
- Import
ReactiveFormsModule
in your current angular module - Import
FormBuilder
andValidators
from@angular/forms
into your component - Inject into the component the
FormBuilder
- Create a public
formName
variable by usingFormBuilder
- Describe your forms using:
ControlGroup
- Add some validators (custom?)
- Update the form to use
Working based on 12 source code
Following slides:
- Create a Feature module called
ProductModule
- Create a Shared module called
SharedModule
- Refactor
AppModule
if necessary - Create a
ProductRoutingModule
and aAppRoutingModule
to split down routing configuration - Optional: Create a
CoreComponent
to handle all services once in your application
No challenge here!
Working based on 13 source code
No challenge here!
Working based on 15 source code