How do you get the current route?

Posted by Andre Scott | Updated on | Angular Interview


In Angular, there is an url property of router package to get the current route. You need to follow the below few steps, 1. Import Router from @angular/router 2. Inject router inside constructor 3. Access …

What is host property in css?

Posted by Jennifer | Updated on | Angular Interview


What is host property in css? The :host pseudo-class selector is used to target styles in the element that hosts the component. Since the host element is in a parent component’s template, you can’t reach …

Can you give an example of built-in validators?

Posted by Jennifer | Updated on | Angular Interview


In reactive forms, you can use built-in validator like required and minlength on your input form controls. For example, the registration form can have these validators on name input field: Whereas in template-driven forms, both …

What are the types of validator functions?

Posted by Jennifer | Updated on | Angular Interview


In reactive forms, the validators can be either synchronous or asynchronous functions: Sync validators: These are the synchronous functions which take a control instance and immediately return either a set of validation errors or null. Also, …

How do you reset the form?

Posted by Jennifer | Updated on | Angular Interview


How do you reset the form? In a model-driven form, you can reset the form just by calling the function reset() on our form model. For example, you can reset the form model on submission …

What are the state CSS classes provided by ngModel?

Posted by Jennifer | Updated on | Angular Interview


The ngModel directive updates the form control with special Angular CSS classes to reflect it’s state. Let’s find the list of classes in a tabular format: Form control state If true If false Visited ng-touched …

How do you verify the model changes in forms?

Posted by Jennifer | Updated on | Angular Interview


You can add a getter property(let’s say, diagnostic) inside component to return a JSON representation of the model during the development. This is useful to verify whether the values are really flowing from the input …

What is the purpose of FormBuilder?

Posted by Jennifer | Updated on | Angular Interview


FormBuilder is used as syntactic sugar for easily creating instances of a FormControl, FormGroup, or FormArray. This is helpful to reduce the amount of boilerplate needed to build complex reactive forms. It is available as …

How do you update specific properties of a form model?

Posted by Jennifer | Updated on | Angular Interview


You can use patchValue() method to update specific properties defined in the form model. For example, you can update the name and street of certain profile on click of the update button as shown below. …

What are the differences between reactive forms and template driven forms?

Posted by Jennifer | Updated on | Angular Interview


Below are the main differences between reactive forms and template driven forms: Feature Reactive Template-Driven Form model setup Created(FormControl instance) in component explicitly Created by directives Data updates Synchronous Asynchronous Form custom validation Defined as …

What are dynamic forms?

Posted by Pinki | Updated on | Angular Interview


Dynamic forms is a pattern in which we build a form dynamically based on metadata that describes a business object model. You can create them based on reactive form API.

What are the types of injector hierarchies?

Posted by Jennifer | Updated on | Angular Interview


There are two types of injector hierarchies in Angular ModuleInjector hierarchy: It configure on a module level using an @NgModule() or @Injectable() annotation. ElementInjector hierarchy: It created implicitly at each DOM element. Also it is empty by …

What is an optional dependency?

Posted by Jennifer | Updated on | Angular Interview


The optional dependency is a parameter decorator to be used on constructor parameters, which marks the parameter as being an optional dependency. Due to this, the DI framework provides null if the dependency is not …

How do you configure injectors with providers at different levels?

Posted by Jennifer | Updated on | Angular Interview


You can configure injectors with providers at different levels of your application by setting a metadata value. The configuration can happen in one of three places, In the @Injectable() decorator for the service itself In the @NgModule() decorator for …

How do you change the settings of zonejs?

Posted by Jennifer | Updated on | Angular Interview


You can change the settings of zone by configuring them in a separate file and import it just after zonejs import. For example, you can disable the requestAnimationFrame() monkey patch to prevent change detection for …