The tutorial for Angular Hero Editor states that to add a hero property to the HeroesComponent for a hero named "Windstorm" you should edit heroes.component.ts and add: hero = 'Windstorm';
However, it does not say where the code should be placed.
Where should I add the code to the file? Below is the contents of the file:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-heroes',
templateUrl: './heroes.component.html',
styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
constructor() {
}
ngOnInit() {
}
}
Create Angular components to display hero details and show an array of heroes. Use one-way data binding for read-only data. Add editable fields to update a model with two-way data binding. Bind component methods to user events, like keystrokes and clicks. Enable users to select a hero from a master list and edit that hero in the details view.
If ng serve is still running, the browser should refresh and display both the application title and the hero's name. A real hero is more than a name. Create a Hero interface in its own file in the src/app directory . Give it id and name properties. Return to the HeroesComponent class and import the Hero interface.
Angular needs to know how the pieces of your application fit together and what other files and libraries the application requires. This information is called metadata. Some of the metadata is in the @ Component decorators that you added to your component classes.
Build a simple hero editor. Follow the setup instructions for creating a new project named . node_modules ... When you're done with this page, the app should look like this . This command runs the TypeScript compiler in "watch mode", recompiling automatically when the code changes.
Make hero = 'Windstorm';
a property of the component.
export class HeroesComponent implements OnInit {
hero = 'Windstorm';
constructor() {
}
ngOnInit() {
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With