0
0
Angularframework~20 mins

Enums in Angular applications - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Angular Enums Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does Angular handle enum values in templates?
Given this enum and component code, what will be displayed in the template?

export enum Status {
  Active = 'ACTIVE',
  Inactive = 'INACTIVE'
}

@Component({
  selector: 'app-status',
  template: `<p>Status: {{ status }}</p>`
})
export class StatusComponent {
  status = Status.Active;
}
Angular
export enum Status {
  Active = 'ACTIVE',
  Inactive = 'INACTIVE'
}

@Component({
  selector: 'app-status',
  template: `<p>Status: {{ status }}</p>`
})
export class StatusComponent {
  status = Status.Active;
}
AStatus: ACTIVE
BStatus: 0
CStatus: Active
DStatus: undefined
Attempts:
2 left
💡 Hint
Remember enums with string values show the string, not the key name.
📝 Syntax
intermediate
2:00remaining
Which enum declaration is valid in Angular TypeScript?
Choose the correct enum declaration syntax that will compile without errors in Angular.
Aenum Colors = { Red: 'RED', Green: 'GREEN', Blue: 'BLUE' }
Benum Colors { Red: 'RED', Green: 'GREEN', Blue: 'BLUE' }
Cenum Colors { Red = 'RED', Green = 'GREEN', Blue = 'BLUE' }
Denum Colors { 'Red' = 'RED', 'Green' = 'GREEN', 'Blue' = 'BLUE' }
Attempts:
2 left
💡 Hint
Look for the correct enum key-value syntax in TypeScript.
🔧 Debug
advanced
2:00remaining
Why does this Angular component throw an error when using an enum in the template?
Consider this code snippet:

export enum Mode {
  Light,
  Dark
}

@Component({
  selector: 'app-theme',
  template: `<p>Current mode: {{ Mode.Dark }}</p>`
})
export class ThemeComponent {
}

What is the cause of the error when rendering the template?
Angular
export enum Mode {
  Light,
  Dark
}

@Component({
  selector: 'app-theme',
  template: `<p>Current mode: {{ Mode.Dark }}</p>`
})
export class ThemeComponent {
}
AThe enum Mode is shadowed by the class property, causing a runtime error.
BThe template syntax {{ Mode.Dark }} is invalid and should be {{ Mode['Dark'] }}.
CThe enum values are numbers, so Angular cannot display them directly in templates.
DThe enum Mode is not accessible in the template because it is not assigned to a class property.
Attempts:
2 left
💡 Hint
Think about how templates access class properties and variables.
state_output
advanced
2:00remaining
What is the value of 'currentStatus' after this Angular component runs?
Given this enum and component code:

export enum Status {
  Pending = 1,
  Approved,
  Rejected
}

@Component({
  selector: 'app-request',
  template: `<p>Status: {{ currentStatus }}</p>`
})
export class RequestComponent {
  currentStatus = Status.Approved;
}

What is the value of 'currentStatus'?
Angular
export enum Status {
  Pending = 1,
  Approved,
  Rejected
}

@Component({
  selector: 'app-request',
  template: `<p>Status: {{ currentStatus }}</p>`
})
export class RequestComponent {
  currentStatus = Status.Approved;
}
AApproved
B2
C1
Dundefined
Attempts:
2 left
💡 Hint
Numeric enums auto-increment from the first value.
🧠 Conceptual
expert
2:00remaining
Why should enums be assigned to component properties for template use in Angular?
In Angular, why is it necessary to assign an enum to a component property before using it in the template?
ABecause Angular templates can only access instance properties, not imported symbols directly.
BBecause enums are not supported in Angular templates unless converted to strings first.
CBecause assigning enums to properties improves runtime performance by caching values.
DBecause Angular requires all variables in templates to be declared with @Input decorators.
Attempts:
2 left
💡 Hint
Think about the scope of variables accessible in Angular templates.