Given the Angular component with selector app-greeting and template <p>Hello, Angular!</p>, what will be the output when used as <app-greeting></app-greeting> in another component's template?
import { Component } from '@angular/core'; @Component({ selector: 'app-greeting', template: '<p>Hello, Angular!</p>' }) export class GreetingComponent {}
Think about how Angular replaces component selectors with their templates.
Angular replaces the app-greeting tag with the component's template content, so the output is the paragraph with 'Hello, Angular!'.
Which of the following selector values is conventional for an Angular component?
Angular component selectors are usually element selectors.
Angular component selectors are typically element selectors like 'app-header'. Class selectors ('.app-header'), ID selectors ('#app-header'), and attribute selectors ('[app-header]') are valid but more commonly used for directives.
<app-footer></app-footer>?Given this component code, why does using <app-footer></app-footer> in a template not render anything?
import { Component } from '@angular/core'; @Component({ selector: '[app-footer]', template: '<footer>Footer content</footer>' }) export class FooterComponent {}
Check the selector type and how it matches HTML elements.
The selector '[app-footer]' means the component matches elements with the attribute 'app-footer'. Using
Consider this Angular component with selector div[app-highlight]. What will be rendered when used as below?
<div app-highlight>Text 1</div> <span app-highlight>Text 2</span>
import { Component } from '@angular/core'; @Component({ selector: 'div[app-highlight]', template: '<div style="color: red;">Highlighted</div>' }) export class HighlightComponent {}
Think about how Angular matches selectors and replaces elements.
The selector 'div[app-highlight]' matches only
Why is it recommended to use custom prefixes like app- in Angular component selectors instead of common HTML tags like header or footer?
Think about how browsers and Angular handle native HTML tags versus custom elements.
Using common HTML tags as selectors can cause conflicts because browsers already recognize those tags natively. Using prefixes like 'app-' creates unique custom elements that Angular can safely replace without conflicts.