Complete the code to make the property accessible only within the component class.
export class MyComponent { [1] title = 'Hello Angular'; }
Using private makes the property accessible only inside the component class.
Complete the code to allow the property to be accessed by this class and its subclasses.
export class BaseComponent { [1] data = 42; } export class ChildComponent extends BaseComponent { showData() { console.log(this.data); } }
protected allows access inside the class and its subclasses.
Fix the error in the code by choosing the correct access modifier for the method used in the template.
export class MyComponent { [1] getMessage() { return 'Welcome!'; } } <!-- In template --> <p>{{ getMessage() }}</p>
Template can only access public members of the component.
Fill both blanks to declare a property that can be read publicly but only set privately.
export class UserComponent { [1] _name = 'Alice'; [2] get name() { return this._name; } }
The backing field is private to restrict setting, and the getter is public to allow reading.
Fill all three blanks to create a component with a protected method, a private property, and a public getter.
export class ProfileComponent { [1] _age = 30; [2] get age() { return this._age; } [3] updateAge(newAge: number) { this._age = newAge; } }
The property is private to hide it, the getter is public to allow reading, and the method is protected to allow access in subclasses but not outside.