Professional Documents
Culture Documents
Angular - The Hero Editor
Angular - The Hero Editor
The application now has a basic title. Next, create a new component to
shell.
For the sample application that this page describes, see the
generates the three �les of the HeroesComponent along with a test �le.
{ } '@angular∕core';
@Component({
selector: 'app-heroes',
templateUrl: '.∕heroes.component.html',
styleUrls: ['.∕heroes.component.css']
})
{
}
You always import the Component symbol from the Angular core library
PROPERTIES DETAILS
component's template.
Windstorm .
hero = 'Windstorm';
text that ng generate created and replace it with a data binding to the
heroes.component.html
{{hero}}
src/app/app.component.html
{{title}}
If ng serve is still running, the browser should refresh and display both
the application title and the hero's name.
Create a interface
A real hero is more than a name.
Create a Hero interface in its own �le in the src∕app directory . Give it
src/app/hero.ts
{
id: number;
name: ;
}
{ } '@angular∕core';
{ } '..∕hero';
@Component({
selector: 'app-heroes',
templateUrl: '.∕heroes.component.html',
styleUrls: ['.∕heroes.component.css']
})
{
hero: = {
id: 1,
name: 'Windstorm'
};
}
The page no longer displays properly because you changed the hero
{{hero.name}} Details
id: {{hero.id}}
name: {{hero.name}}
src/app/heroes/heroes.component.html
The browser refreshes and now the hero's name is displayed in capital
letters.
Pipes are a good way to format strings, currency amounts, dates, and
other display data. Angular ships with several built-in pipes, and you can