Interview Questions Angular - amitbhilagude/userfullinks GitHub Wiki
Why angular so popular
No more DOM manipulation which javascript and jquery used to. Angular Takes care of it.
Partial rendering will never refresh the page and gives a good experience for SPA.
Use of typescript gives strong typing for developers and more maintainable code.
Angular Architecture
Module
Components
View- Template
Component - Class which contains business logic
Both are bound to the property or event binding
Services
Doesn't have UI and injectable in Components.
SPA
One HTML renders from Server
Angular components get renders based on each view.
Angular starter app or basic app
ng new myapp
Angular Starter flow
Index.html: It has reference of app-root component. Runtime refers main.js
Main.ts: It is transpired to the main.js. it has the functionality to bootstrap the main module.
Main Module: The main module has app-root components and views from it will get rendered.
Metadata
Metadata in angular is to inform Angular on how to proceed.
It has annotations like @ e.g. @Ngmodule, @component, @injectable. These annotations are called Decorator.
Constructor vs ngOninit
Constructor is from typescript concept and it gets called when an object gets initialized,
ngonit is an angular page hook life cycle. In terms of flow constructor gets called and the ngonit when the component gets rendered. Any property you want to access from view then it needs to defined in a ngonit.
Angular Page hook life cycle
Similar to .net where every angular component has life cycle events.
They are categorized into two. First time and any change in UI. ngonit for the first time. ngchanges is for any UI-level updates.
Angular Directive
Anything tag added in UI is directive e.g. Ngif, ngfor, etc. They are used to manipulate DOM elements
Three types
Structural Directive: It used to change the structure DOm e.g. Ngfor going to add additional HTML tags in dom
Behaviour Directive: It used to change the behavior of directive e.g. ng-hide will hide the dom
Component directive: Custom directive created for angular. e.g. Usercontrol
Angular dependency Injection and Services.
Explain how dependency injection works and how services are used in the dependency injection pattern.
Httpclient
Subscriber and observable
Lazy Loading
Load on demand.
THis is implemented for modules only and if you wish to load a module dynamically on demand.
It is implemented using routing where Route has a path which will bound to component and Lazyload property where we can provide module relative
path.
Canactivate
This specifically used for routing and if you wish to activate the route based on a certain condition
It can method and based on the return type of method. It can be decided