Bird
0
0

Which of the following is the correct way to define a standalone component in Angular 17+?

easy📝 Syntax Q12 of 15
Angular - Fundamentals
Which of the following is the correct way to define a standalone component in Angular 17+?
A<code>@Component({ standalone: true, selector: 'app-sample', template: '<p>Hello</p>' }) export class SampleComponent {}</code>
B<code>@NgModule({ declarations: [SampleComponent] }) export class SampleModule {}</code>
C<code>function SampleComponent() { return '<p>Hello</p>'; }</code>
D<code>class SampleComponent extends Component {}</code>
Step-by-Step Solution
Solution:
  1. Step 1: Recall Angular 17+ standalone component syntax

    Standalone components use @Component with 'standalone: true' and define selector and template.
  2. Step 2: Check each option

    @Component({ standalone: true, selector: 'app-sample', template: '

    Hello

    ' }) export class SampleComponent {}
    matches the correct syntax; A is plain function, B is for modules, D is invalid class extension.
  3. Final Answer:

    @Component({ standalone: true, selector: 'app-sample', template: '<p>Hello</p>' }) export class SampleComponent {} -> Option A
  4. Quick Check:

    Standalone component = @Component with standalone: true [OK]
Quick Trick: Standalone components need 'standalone: true' in @Component [OK]
Common Mistakes:
  • Using @NgModule instead of standalone component
  • Defining component as plain function
  • Extending non-existent Component class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes