2

in the Angular tutorial https://angular.io/tutorial/toh-pt1#selector, I dont understand the sentence: "The CSS element selector, 'app-heroes', matches the name of the HTML element that identifies this component within a parent component's template." I don't know what is like for a css selector, because I cannot find anything that matches the name of some HTML element.. there is no HTML element with the name app-heroes or similar... How does this work?

I only have a folder structure /src/app/heroes, where my heroes components are defined. Does it construct a name consisting of "parentfolder-folder"? and what exactly will be referenced by the css element selector ?

2 Answers 2

1

I dont understand the sentence: "The CSS element selector, 'app-heroes', matches the name of the HTML element that identifies this component within a parent component's template."

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})

As you can see in the @Component it defines the selector with the value app-heroes this means that you will use app-heroes to be like html element (eg. <div> </div> therefore you will use <app-heroes></app-heroes>) to be able to show the view of HeroesComponent.

Sign up to request clarification or add additional context in comments.

Comments

1

Scroll down where it says Show the HeroesComponent view. There you will see HTML:

<h1>{{title}}</h1>
<app-heroes></app-heroes>

So your CSS selector app-heroes matches this HTML node <app-heroes></app-heroes>. Same as CSS selector h1{} matches <h1></h1>

2 Comments

thanks nice, and that basically means, that my "template" or rather selector which refers to <app-heroes> will be bound inside the other html document? and which part gets replaced? will the whole code of my heroes.component.ts placed at that point or will only my heroes.component.html file be added at that place?
@user2883596 All code from AppHeroes component will be placed as child of app-heroes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.