Lab 1.2: Template
Objectives
- Create and run an Angular project
- Understand the structure of an Angular project
- Playing with variables in the template
- Creating a type/interface model and using it in the code
Instructions
- Fetch the project from the repository
- Install the dependencies using
npm install - Run the project using
ng serve
Simple modifications
- In the app.component.ts file, modify the
titlevariable to display the name you want for your application. Doing this, you will see the new name in the body of your component. It will not be displayer in the header and footer yet. - Create a
currentYearvariable and extract the year from a Date.
currentYear = new Date().getFullYear();
- Replace the date in the footer with the
currentYearvariable.
Creating a model and using it
- In a file
src/app/model/album.model.tsCreate an Album interface with the following properties:title,artist,releaseDate,price,hidden,genre,description.
export interface Album {
title: string;
artist: string;
releaseDate: Date;
price: number;
genre: string;
hidden: boolean;
description: string;
}
- Create a variable called
albumOfTheDayin theapp.component.tsfile and assign an object that respects the Album interface using an album you like.
albumOfTheDay: Album = {
// your album properties here
};
- Display the
albumOfTheDayin the template using thealbumOfTheDayvariable properties.
Click event
- When clicking on the button, replace the
albumOfTheDaywith another value. Template should be updated automatically. You will need to create a function for that (use theclickevent to call that function).
ngModel
- We want the search box to be able to modify a variable called searchTerm
- Create a variable
searchTermin theapp.component.tsfile.
searchTerm: string = '';
- Bind the input to the
searchTermvariable using[(ngModel)]. - Display the
searchTermvariable in the template in front of "You are searching:"
[HINT]: Dont forget to import the FormsModule in the app.module.ts file