Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unclear instructions in Angular Hero Editor project

Tags:

angular

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() {
}

}
like image 561
SimonRH Avatar asked Nov 21 '17 20:11

SimonRH


People also ask

How do I display a list of Heroes in angular?

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.

How do I make a hero in Ng serve?

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.

What does @angular need to know about my application?

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.

How do I build a hero editor in typescript?

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.


1 Answers

Make hero = 'Windstorm'; a property of the component.

export class HeroesComponent implements OnInit {
  hero = 'Windstorm';

  constructor() {    
  }

  ngOnInit() {
  }
}
like image 124
zgue Avatar answered Oct 21 '22 03:10

zgue