we will discuss the topmost very important Angular 2,3..7,8 interview questions.this questions are commonly asked in every interview.
What is the difference between angularJs and angular Applications?
- angularJs application is slow compared to angular applications and easy to implement this application
- Angularjs core concept was $scope, without scope we can’t communicate between views and controller.
- For communicating with views/templates it require controllers.
- Angular is a single pages application and framework .this application pages will not run on the browser directly.
- angular application is very fast compared to angularJs applications and complex to implement this application.
- Angular2 is using Zone.js for detecting changes made in the DOM.
- It’s build with components.Template Directives + controllers = components.
What is typescript?
Benefits of TypeScript:
before executing the script the compiler will generate syntax errors if any error is raised easily to finding the errors.
the major benefits of typescript are OOPs principles by using these principals we will reusable and easier to manage the code.
Writing code in typescript is more predictable and is generally easier to debug.
What are Directives and types in angular 4?
In angular Directives are the classes that can change the behavior or appearance of the components by using CSS Classes, CSS Styles, and events.
There are three kinds of directives in Angular:
- Components—directives with a template.
- Structural directives—change the DOM layout by adding and removing DOM elements.
- Attribute directives—change the appearance or behavior of an element
What is the main Feature of Modules?
Main differences between root module and feature module are,
- Root module launches the application whereas the feature module will get imported to extend the application.
- The feature module can expose or hide its implementation from other modules.
- Feature module helps us to partition the application into various sets of functionalities that will be focused on an application business domain, user workflow, and facilities like forms, Http, routing (or) a collection of related utilities. Whereas we can do everything within the root module.
- Feature module doesn’t import BrowerModule but CommonModule because the feature is just a part of RootModule so no need to import Browser Module in FeatureModules. To make our feature module to be platform-independent we only need to import CommonModule.
What is Lazy Loading a Module
Lazy loading is the concept of loading the required piece of code only when it’s on-demand, i.e. when NgModule launches the angular application it loads all the components and modules which are declared within, due to this application startup time will be increased and this show impact on the performance of our application.
- Eager Component should load in start-up
- Lazy Component should load only when we navigate to its module.
Can you explain about HTML form in angular?
In most of the front end applications, we use HTML forms for grouping HTML elements and we provide validations using HTML5 attributes like required, minlength, maxlength, pattern etc.
And every forms do such similar tasks across all applications they are:
- Maintain the form state
- Tracking which part of the form is valid and which part is invalid
- Displaying error message to how to make form valid
- Form submitting and resetting
Similarly angular framework provides us alternative strategies to handle the forms they are:
- Template Driven Forms (similar to Angular1 forms)
- Model-Driven /Reactive Forms
what are the Angular provides to us built-in validators?
Angular provides us built-in validators via standard HTML5 attributes such as, custom validation
And our FormContol( ) can be overloaded by providing the Validators
- first parameter: Initial value of the control
- second parameter: It contains either a single validator or list of validators
Modify the above FormComponent as follows,
- firstName (required, pattern which allows only alphanumeric but not special characters)
- lastName (required, maxlength of 10 characters)