0
0
Angularframework~10 mins

Type annotations in components in Angular - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a type annotation for the component's title property.

Angular
export class AppComponent {
  title: [1] = 'Hello Angular';
}
Drag options to blanks, or click blank then click option'
Aboolean
Bnumber
Cstring
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using number or boolean types for text properties.
Not adding any type annotation.
2fill in blank
medium

Complete the code to type the input property correctly.

Angular
import { Component, Input } from '@angular/core';

@Component({
  selector: 'app-child',
  template: '<p>{{name}}</p>'
})
export class ChildComponent {
  @Input() name: [1];
}
Drag options to blanks, or click blank then click option'
Anumber
Bstring
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Typing the input as number or boolean incorrectly.
Leaving the type as any.
3fill in blank
hard

Fix the error by adding the correct type annotation for the count property.

Angular
export class CounterComponent {
  count: [1] = 0;
}
Drag options to blanks, or click blank then click option'
Anumber
Bboolean
Cstring
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Typing count as string or boolean.
Not adding any type annotation.
4fill in blank
hard

Fill both blanks to type the event handler method parameters correctly.

Angular
export class ButtonComponent {
  onClick(event: [1], value: [2]) {
    console.log(event, value);
  }
}
Drag options to blanks, or click blank then click option'
AMouseEvent
Bstring
Cnumber
DEvent
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic Event instead of MouseEvent.
Typing value as number instead of string.
5fill in blank
hard

Fill all three blanks to type the component properties correctly.

Angular
export class ProfileComponent {
  username: [1];
  age: [2];
  isActive: [3] = true;
}
Drag options to blanks, or click blank then click option'
Astring
Bnumber
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up types between properties.
Not adding type annotations.