TypeScript class is one that is used to create components. This genre of class is then decorated with the "@Component" decorator. The decorato’s purpose is to accept a metadata object that provides relevant information about the component.
198 | | 55 | Promises vs Observables
199 | | 56 | Subject vs BehaviorSubject
200 | | 57 | What are the advantages of Reactive forms over Template driven forms
201 | | 58 | Why need Lazy loading ?
202 | | 59 | How can you share data between components?
203 | | 60 | What is Two way data binding?
204 | | 61 | Is constructor a part of angular ?
205 | | 62 | What is Dependency Injection?
1. Using Dependency Injection we move the creation of binding dependent object otside of the class that depend on them. 2. DI keeps the code more flexible testable and mutable. 3. Class can inherit external logic without having to create on its own. 4. DI benefits directives, pipes and components.
Consider all the components of an application performing common tasks like accessing database, rendering images on the view etc. To avoid rewriting of code, angular services can be used. These services can then be injected into the components that require that service.
206 | | 63 | What is Webpack?
Webpack is a module bundler that lets you compile JavaScript modules (Files, Images, Fonts, JS, CSS, HTML, etc.). Webpack offers multiple functions, like merging modules, code minimization (or minimizing code by eliminating spaces, remarks, junk code, and code reduction), SASS or TypeScript compiling, integration with npm, and other features.
207 |
208 | https://flatlogic.com/blog/what-is-webpack-flatlogic-glossary/
209 |
210 | Webpack is also able to handle multiple other tasks:
211 |
212 | 1. Assists in pulling your resources all together;
213 | 2. Monitors changes and re-runs tasks;
214 | 3. Can transpile using Babel’s next-generation JavaScript to an older JavaScript standard (ES5), allowing users to use the latest JavaScript features without worrying about whether or not their browser supports them;
215 | 4. Does CoffeeScript to JavaScript translation;
216 | 5. Can converse embedded images into data: URI;
217 | 6. can require() CSS files;
218 | 7. Works with Hot Module Replacement;
219 | 8. May Perform Tree Shaking;
220 | 9. Can split output file into several files so slow page load due to oversized JS-file is prevented.
221 |
222 | | No. | Questions |
223 | | --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
224 | | 63 | Is Webpack needed for Angular?
While the primary purpose of Webpack is to build multiple modules into a single file, it is not bound to only bundling source files.
Usually, webpack is hidden behind the Angular command-line tool. Webpack is used internally by angular application to compile ts files ino a single js file.
225 | | 64 | What benefits does Webpack 5 bring to Angular 12?
I understand the build time is increased for you with webpack 5. But if we talk about benefits, Angular has much to offer with webpack 5 and one of them is in terms of modularization using module federation. Webpack 5 is having an important feature of loading remote angular modules and stitching it with angular application at run time and that too without violating rules of zone.js. Its totally a game changer in javascript world. You can read more about it at Module Federation with Webpack 5. With this you can split your codebase with smaller bundle size and during runtime you can dynamically load them on demand, resulting in faster and independent deployments and maintainability.
https://dzone.com/articles/howto-modularize-an-angular-application-by-example
226 | | 65 | The role of Webpack in Angular
227 | https://javascript.plainenglish.io/role-of-webpack-in-angular-part-3-of-series-what-angular-is-5058d445e45c
228 |
229 | 1. angular CLI uses a tool called webpack which is a build automation tool it gets all our scripts and stylesheets combines them outs them in a bundle and minifies that bundle and this is for optimization.
230 | i) polyfills.bundle.js which includes all the scripts to fill the gap between the version of Javascript that Angular needs and the version of Javascript supported by most browsers.
231 | ii) main.bundle.js which includes all the source code of our application.
232 | iii) styles.bundle.js which includes all our stylesheets. Here stylesheets are stored in a Javascript bundle.
233 | iv) vendor.bundle.js which includes all the third-party libraries.
234 | 2. whenever we make changes in any of our file html, type-scripts or styles the webpack automatically recompile our application and refreshes our bundles. Go back to the browser and enter http://localhost:4200/ . The change in code will appear in browser without even refreshing the page — this is the feature of webpack called hot module replacement or hot module reloading so whenever the source file is modified webpack automatically refreshes our browser.
235 | 3. we don’t have any references to our stylesheets or a script file in our code in index.html — the wepack automatically generate stylesheets & script files and integrate them in index.html dynamically at runtime. All the bundles that webpack generated it also injected them in index.html — everything happen dynamically at runtime.
236 | 4. all our Styles are compiled into a Javascript bundle. And webpack is behind to automatically generate these bundles at compile time. It also injected them in index.html at runtime.
237 | | No. | Questions |
238 | | --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
239 | | 66 | What is Modularizing ?
Modularizing the application has helped the startup performance and shows how bigger downloads can be split. In this case, the initial load was more than halved. If the files are gzipped it is below 300 kb.
TypeScript made it easy to split the code into ,odules. Splitting the templates was not as easy. The Angular compiler did not show the missing modules. The errors are shown at run time. It would be nice if Angular would have a feature that checks that all used modules are imported at compile time.
Splitting an existing application into modules is quite easy and takes only a reasonable amount of effort. The better approach is to start the development of an application with modules, placing related components in modules with a common base route and subroutes to the components. The required imports can then be added during the development process. That keeps the startup performance okay, with little extra cost.
https://dzone.com/articles/howto-modularize-an-angular-application-by-example
240 | | 67 | What is NgModule ?
Inside of the @NgModule operator, we define all the properties of the module.
Bootstrap ::=> Defines the root-component of the Application. Only use this in the AppModule.
Exports ::=> We define the components, directives or pipes we want to export here.
Declarations ::=> Inside of the declarations array, we define all the components, directives and pipes, that are declared and used inside this module.
Imports ::=> Your module can import as many sub-modules as you like. For example, if you want to use the HttpClient, you will need to import the HttpClientModule.
Providers ::=> We define any @Injectables, required by the module, here. Any sub-components or modules can then get the same instance of that @Injectable via dependency injection. In the case of the AppModule, these @Injectables are application-scoped.
241 | | 68 | What is Angular CLI?
Angular CLI, a command-line interface tool for Angular that you can use to initialize, build, scaffold, and prolong Angular applications directly from a command shell. Hence, we can say it is the official tool for initializing and operating with Angular projects. It helps you from out in the complex configurations and builds tools like TypeScript, Webpack, etc.
Although it uses Webpack to have all the packaging, importing, Browser Link, etc., you do not need to know how Webpack functions or how it needs to figure out to run in different environments or on other types of machines.
242 | | 69 | What is Tree Shaking ?
Tree shaking is a technique used to eliminate unused modules from the final bundle file of an application, reducing the download size and improving performance. The Angular CLI uses the Webpack bundler, which supports tree shaking from version 2.
243 | Tree shaking refers to dead code elimination. It means that unused modules will not be included in the bundle during the build process.
244 |
245 | When we import and export modules in JavaScript, most of the time there is unused code floating around. Excluding that unused code (also referred as dead code) is called tree shaking.
246 |
247 | Utilizing the tree shaking and dead code elimination can significantly reduce the code size we have in our application. The less code we send over the wire the more performant the application will be.
248 |
249 | 
250 | 
251 | | No. | Questions |
252 | | --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
253 | | 70 | What is fixture?
A fixture is a wrapper for a component and its element & template.
254 | const fixture = TestBed.createComponent(BannerComponent);
255 | TestBed.createComponent() creates an instance of the BannerComponent, adds a corresponding element to the test-runner DOM, and returns a ComponentFixture.
256 |
257 | it('should have with "banner works!"', () => {
258 | const bannerElement: HTMLElement = fixture.nativeElement;
259 | const p = bannerElement.querySelector('p')!;
260 | expect(p.textContent).toEqual('banner works!');
261 | });
262 | | No. | Questions |
263 | | --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
264 | | 71 | Web worker vs Service worker in angular ?
Web worker allows scripts to run in the background in separate threads to prevent scripts from blocking one another on the main thread. Use cases : CPU-intensive tasks such as image processing, video encoding, and audio decoding
Service workers are a proxy between the browser and the network. By intercepting requests made by the document, service workers can redirect requests to a cache, enabling offline access. Use cases : Network-related tasks such as caching resources, intercepting requests, and handling push notifications
265 | | 72 | How will write testcase for methods in angular ?
spyOn is used to mock the methods and get dummy return value using .and.returnValue(). You can use spyOn to check like that the particular method is called or not called.
266 | | 73 | What is the use of spyOn ?
1. spyOn is used to mock the methods and get dummy return value using .and.returnValue()
2. spyOn can call original function using .and.callThrough()
spyOn is used to mock external dependencies of the code being tested are replaced by dummy implementations so that the code to be tested can be controlled and test runs can be more quick and reliable. All of the external dependencies like services, pipes, directives should be mocked to provide the expected level of isolation.
267 | | 74 | Third Party libraries in angular mostly used?
1. ngx-logger (https://www.npmjs.com/package/ngx-logger) 2. trackjs (https://www.npmjs.com/package/trackjs)
268 | | 75 | Root module vs Feature modules ?
Root module is simple a modules that can be bootstrapped as an application and render itself independently. Feature module is a module that contains related definitions but cannot render itself independently and must ultimately be loaded by a root module.
269 | | 76 | What Is Feature Modules in Angular?
So, in Angular Framework, Feature Module is simply an Angular module with module related kinds of stuff and purpose. But the main difference is that is not the root module of the application. Feature module is just an additional typescript based class with the @NgModule decorator and registered metadata. Feature modules isolate the applications based on the functionality or business operation and it collaborates with the root modules or any other feature modules.
The main purpose of the feature modules is to break down the functionality which focuses on any particular internal business operation or functionality that needs to be dedicated as a module so that we can achieve modularity in the application. With the help of feature modules, we also can restrict the responsibility of the root modules and help the root module to keep it thin and small.
270 | | 77 | Why Mocking is needed in Angular?
Mocking is a technique in unit testing in which the external dependencies of the code being tested are replaced by dummy implementations so that the code to be tested can be controlled and test runs can be more quick and reliable. In simple words, Mocking or Mock implementation is creating a dummy version of an external or internal service on which the code to be tested depends. Mocking in Jasmine Karma is generally replacing external dependencies with mock functions.
Whenever we encounter a dependency while unit testing, the standard practice is to mock or stub the dependency.
271 | | 78 | Difference between integration test and unit test?
1. Integration test includes (“integrates”) the dependencies. Unit test replaces the dependencies with fakes in order to isolate the code under test.
2. Unit test is written for individual units or components of an application. Integration tests is written for two or more units. An integration test does not test a complete workflow, nor does it test an isolated unit.
272 | | 79 | What is End-to-end testing ?
In E2E testing, you test the workflow of your application from start to finish. In other words, you test for actions that real users can perform on your app to check that desired outputs are obtained.
273 | Intercepting API calls to return fixed data
274 |
275 | 
276 |
277 | | No. | Questions |
278 | | --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
279 | | 80 | How will test native element in angular ?
We can access HTML elements using fixture. It is used to get “DebugElement” for a DOM object. DebugElement is an Angular class that contains all kinds of references and methods relevant to investigate an element as well as component. nativeElement returns a reference to the DOM element which can also come under debugElement as stated above.
280 | It works for querying both class something like (fixture.debugElement.nativeElement.querySelector('.shan')) as well as id.
281 |
282 |
Hey there
283 | We can use below ways to get it in unit testing:
284 |
285 | ```
286 | fixture.debugElement.query(By.css('#shan'))
287 | fixture.debugElement.nativeElement.querySelector('#shan')
288 | document.getElementById('#shan')
289 | ```
290 | | No. | Questions |
291 | | --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
292 | | 81 | How will identify, diagnose and fix memory leaks in the application?
293 | In javascript, memory should be cleared up automatically using a thing called Garbage collector. Javascript is a language who ha garbage collector meaning you don't have to manage your memory manually. It gets cleared automatically & assigned automatically.
294 |
295 | Symptons ::===> 1. Page unresponsive 2. browser simply gets slow and you cann't switch tab anymore 3. Your computer is become slow becuase your browser eats up more and more RAM of your computer
296 |
297 | Reasons & Solutions of memory leaks ::===>
298 | 1. window.x = 10 it's a global variable. you probably heard many times is a realy bad practive to have global variables.
299 | window.calc = function() => {} calc is a fuction and imagine it does something heavy inside. That's obviously gonna stay on the root becuase root is accessing it and garbage collectors think that is always active becuase it sits on the root.
300 | First thing you can do use strict to prevent you from these memory leaks becuae it i going to throw errors as soon as you have global variables. Or simple not use any global variables.
301 | 2. When you have setTimeout or setInterval and you have a callback inside and have some dependencies. Dependencies are bad in timeout as long as you don't clear the timeout.
302 | ```
303 | setTimeout(() => {
304 | let node = document.getElementById('demo');
305 | }, 1000);
306 | node.remove()
307 | ```
308 | let's imagine there is some node inside setTimeout function and usually when you delete node from your javascript. now i am removing the node using node.remove(). but this timeout always going to keep a reference to this even if it's deleted.
309 | So make sure you are always clears timeout. To clear timeout, first assinging your timeout to some kind of a variable and quickly call clearTimeout() with variable inside it. In that way when timeout will be cleared, all references inside it also going to be garbage collected.
310 | 3. make sure you delete it from object itself otherwise it's never going to get garbage collected.
311 | ```
312 | let nodes = {
313 | btn: document.getElementById('demo')
314 | }
315 | document.getElementById('demo').remove();
316 | ```
317 | you have to do the
318 | delete nodes.btn
319 |
320 | Diagnose ::===> analyze Memory Leaks with Chrome DevTools:
321 | 1. Open DevTools 2. Go to the Memory panel 3.select the “Allocation instrumentation on timeline” radio button 4.Press the Start button
322 | 1. open the Chrome Dev Tools 2. open the panel on the right 3. click on More Tools > Performance Monitor
323 |
324 | | No. | Questions |
325 | | --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
326 | | 82 | What are Services in Angular?
Services helps us to share common business logic, data and functions with different components of an Angular application. They are implemented through dependency injection.
327 | | 83 | When should I use RxJS in Angular Application?
RxJS (Reactive Extensions for JavaScript) is a powerful library that allows developers to handle asynchronous data streams in a functional and efficient way. Angular heavily relies on RxJS for handling asynchronous operations, such as handling HTTP requests, event handling, and managing state changes. When working with Angular, you'll frequently use RxJS Observables to manage data streams, especially when interacting with APIs. In addition to its use in Angular development, RxJS is also a popular choice for reactive programming in other JavaScript frameworks and libraries, such as React, Vue. js, and Node.
328 | | 84 | What is State Management?
State management refers to the process of managing the state of an application. The state is a representation of the data at a given point in time. In a typical Angular application, the state includes data such as user information, UI elements, and other application-specific data. Effective state management ensures that the state is consistent, predictable, and easy to debug.
329 | | 85 | Give examples of State management libraries?
In Angular, two popular state management libraries are NgRx and Akita. Both libraries offer robust solutions for handling state in Angular applications, but they differ in their approaches and features.
330 | | 86 | Why needs NGRX in Angular?
NgRx is a reactive state management library for Angular applications. It will work as expected as all the components can get or set the required data from a specific service. But, the actual problem is if we refresh the page we will lose the application state stored in the angular service.
It is based on the Redux pattern and leverages RxJS for reactive programming. NgRx provides a suite of libraries for managing state, side effects, entity collections, and more. NgRx is well-suited for large and complex applications where a strict and predictable state management pattern is needed.
Key Features of NgRx
1) Redux Pattern: NgRx follows the Redux pattern, which is based on three core principles: a single source of truth, state is read-only, and changes are made using pure functions.
2) Store: The store holds the application’s state and serves as the single source of truth.
3) Actions: Actions are dispatched to indicate that something happened.
4) Reducers: Reducers are pure functions that determine how the state changes in response to actions.
5) Selectors: Selectors are pure functions used for obtaining slices of the state.
331 | | 87 | How you will test one service inside another service? To test a service, you set the providers metadata property with an array of the services that you'll test or mock. content_copy let service: ValueService; beforeEach(() => { TestBed. configureTestingModule({ providers: [ValueService] }); }); Then inject it inside a test by calling TestBed.
332 | | 88 | Use of Rxjs of operator ?
Ans. Writing unit testcase of injectable service in angular component. When we have a service for sucscribing inside a component, write spyOn with success & error response. Example : spyOn(dataService, 'makePost').and.returnValue(of(res)); spyOn(dataService, 'makePost').and.returnValue(throwError(() => error));
333 | | 89 | What is TestBed?
TestBed is the primary api for writing unit tests for Angular applications and libraries.
334 | ```TestBed.configureTestingModule({
335 | declarations: [LoginComponent],
336 | providers: [AuthService]
337 | });
338 | // create component and test fixture
339 | fixture = TestBed.createComponent(LoginComponent); (2)
340 |
341 | // get test component from the fixture
342 | component = fixture.componentInstance; (3)
343 |
344 | // UserService provided to the TestBed
345 | authService = TestBed.get(AuthService); (4)
346 |
347 | i) A fixture is a wrapper for a component and its template.
348 | ii) We create an instance of a component fixture through the TestBed, this injects the AuthService into the component constructor.
349 | iii) We can find the actual component from the componentInstance on the fixture.
350 | iv) We can get resolve dependencies using the TestBed injector by using the get function.
351 | ```
352 | | No. | Questions |
353 | | --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
354 | | 90 | Where NGRX or Redux stores state data ?
The store doesn't local/session storage, but all of the entities are stored in memory. A Redux/NGRX state is stored in RAM (internal memory) for all data, do not use Cookies or LocalStorage. The redux store is just a JavaScript object so as long as the machine has enough memory it won't run out.
355 | | 91 | How would you efficiently handle 5000 records from an API call for a dropdown?
https://medium.com/geekculture/simple-way-to-load-small-chunks-of-data-as-you-scroll-in-angular-6a14ec498989 https://medium.com/coding-in-depth/angular-binding-dropdown-with-huge-data-set-af2ef245e548 https://blog.bitsrc.io/3-ways-to-render-large-lists-in-angular-9f4dcb9b65 https://dev.to/pragativerma18/unlocking-the-power-of-api-pagination-best-practices-and-strategies-4b49
356 | | 92 | NGXS vs NGRX?
In NGXS, the application state is stored in a Store, which is defined as a class. The Store class contains properties that represent different sections or nodes of the application state. These properties are initialized at the start of the application and can be modified by actions to update the state. The NgRx library requires us to create a separate reducer. NGXS doesn't have any reducer.
https://danielszpisjak.com/blog/ngxs-vs-ngrx-a-comprehensive-guide-to-state-management-in-angular/
357 | | 93 | Third party package for taking Screenshot or generating PDF?
html2canvas - take "screenshots" of webpages
jspdf - PDF Document creation from JavaScript
358 | | 94 | Third party package for table with CRUD operations?
AG Grid - AG Grid is a feature-rich Data Grid for all major JavaScript frameworks, offering filtering, grouping, pivoting, and more. Free and open-source.
359 | | 95 | What is Nx Monorepo?
Nx monorepo is a development approach where multiple interrelated projects are stored in a single repository, allowing the team of developers to share code and collaborate more seamlessly. It's prevalent in large-scale projects with many independent components.
Imagine you have a collection of distinct but interrelated projects. For instance, you might have an app with its own React frontend and Node.js backend, or two different Angular applications sharing a common collection of components. Monorepos offer an effective solution to organize these distinct but interrelated projects into a single repository.
With a monorepo, all related projects can be housed in a single location, providing clear visibility over all your projects. When you make new changes to one project, you can easily assess how it impacts the others.
Monorepos facilitate seamless code sharing, collaborative work on projects, and synchronization of releases across different projects. However, managing multiple interdependent projects within a single repository requires a capable build tool, such as Nx, to efficiently handle the intricacies.
360 | | 96 | What's Monorepo?
In traditional development workflows, each project has its own repository. This approach can lead to many problems, such as duplication of code, inconsistent dependencies, and poor communication between teams. Monorepo addresses these problems by storing all the projects in a single repository. This approach can make it easier to manage and scale a large codebase, as it allows for better organization, collaboration, and reuse of code. Overall, Monorepos consists of a single repository with multiple projects (think of it as a single big folder containing the entire codebase).
Monorepos became very popular when Google exposed that they were using a single repository for both Gmail and YouTube. In fact, Google uses the monorepo paradigm to organize their code structure. Other companies like Facebook, Twitter, Uber, Netflix, etc. also use monorepos.
Pros : 1) Easier code sharing
2) Better collaboration between teams
3) Easier to maintain external packages/dependencies
4) Single store for code styles, formatting and linting across solutions
5) Test can be run across platform when a change is made to a shared service/feature/package.
Cons : 1) More complex for smaller projects
2) Longer build times (possible)
3) Repository Size
4) Managing dependency
5) Restricting access to apps/libs for certain teams/outsourcers.
There are several tools available to help manage Monorepos, including:
1) NX 2) Lerna 3) Yarn Workspaces
https://medium.com/@magenta2127/monorepo-vs-multi-repo-vs-monolith-7c4a5f476009
361 | | 97 | What is Nx ?
NX is a set of powerful tools and best practices for building and maintaining complex applications. NX provides a number of benefits:
1) A set of powerful command-line tools: NX provides a set of powerful command-line tools for building, testing, and deploying your applications.
2) A set of best practices: NX provides a set of best practices for developing applications in a Monorepo. These best practices help you to write better code, faster.
3)An extensible plugin system: NX provides an extensible plugin system that allows you to add new features and capabilities to your applications.
https://dev.to/thekrprince/getting-started-with-monorepo-using-nx-17j0
362 | | 98 | Is a monorepo a monolith ?
A monolith is an app with related data to this app. While a monorepo may contain a monolith, a monolith is not always in a monorepo. A monolith can be broken up into microservices, but a monorepo can only be broken down into individual repositories. Monorepos are sometimes referred to as monolithic repositories. However, monolithic architecture, used for building self-contained applications, should not be confused with monorepos. Also, It is important to note that monorepos are the exact opposite of multirepos. Monorepos consists of a single repository with multiple projects (think of it as a single big folder containing the entire codebase), while multirepos consists of different projects, with each having its own repository.
363 | | 99 | Monorepo vs MicroFrontend ?
A monolith is an app with related data to this app. While a monorepo may contain a monolith, a monolith is not always in a monorepo.
A monolith can be broken up into microservices, but a monorepo can only be broken down into individual repositories.
The opposite of a monorepo is a multirepo (or a polyrepo) and the opposite of a monolith is distributed microservices.
Monoliths have tightly coupled code bases which can only be decoupled by distributed microservices not by polyrepos or monorepos.
A monorepo is often mistakenly thought to be a monolith - this is when code is colocated with no clear establishment of the relationship or use of such a stratgey.
And a monolith is often broken down into polyrepos each with their own code base to decouple code. This decoupling of code is best when related code bases are still colocated without being tightly coupled.
Monorepos can solve some of the challenges faced by a polyrepo approach - inconsistent tooling, duplication of code, a lack of ease in code sharing.
A combination of monorepos and microservices could solve the challenges of monorepos as monorepos are expensive in terms of data storage. Microservices for the distribution of these data sets across microservices may be one available solution.
A monolith may have different package managers, different stacks and different sets of data configured in different ways all related to a single application.
https://monorepo.tools/
364 | | 100 | npm ci vs npm i ?
npm ci - install exactly what is listed in package-lock.json. keep in mind the package-lock.json file is going to be tied to the specific version of Node that originally created it. all the packages it downloads are going to be for that Node version, even if your Node version is different.
npm install - without changing any versions in package.json, use package.json to write package-lock.json, then install exactly what is listed in package-lock.json
365 | | 101 | Does Angular build use webpack?
Webpack is a popular module bundler, a tool for bundling application source code in convenient chunks and for loading that code from a server into a browser. The Angular build process uses webpack behind the scenes to transpile TypeScript to JavaScript, transform Sass files to CSS, and many other tasks. To understand the importance of this build tool, it helps to understand why it exists.
https://developer.okta.com/blog/2019/12/09/angular-webpack#:~:text=The%20Angular%20build%20process%20uses,limited%20support%20for%20JavaScript%20modules.
366 | | 102 | Extends vs Implements ?
extends: You get all these methods/properties from the parent class so you don't have to implement this yourself.
implements: It is a contract that the class has to follow. The class has to implement at least the following methods/properties.
367 | ```
368 | class Person {
369 | name: string;
370 | age: number;
371 | walk(): void {
372 | console.log('Walking (person Class)')
373 | }
374 | constructor(name: string, age: number) {
375 | this.name = name;
376 | this.age = age;
377 | }
378 | }
379 |
380 | class child extends Person { }
381 |
382 | class man implements Person {
383 | name: string;
384 | age: number;
385 | constructor(name: string, age: number) {
386 | this.name = name;
387 | this.age = age;
388 | }
389 | walk(): void {
390 | console.log('Walking (man class)')
391 | }
392 | }
393 |
394 | (new child('Mike', 12)).walk();
395 | // logs: Walking(person Class)
396 |
397 | ```
398 | | No. | Questions |
399 | | --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
400 | | 103 | @for vs *ngFor ?
The @for block is part of the new control flow syntax introduced in Angular 17.0. The control flow blocks (@if, @for, @switch) are here to replace the 3 structural directives ngIf, ngFor and ngSwitch. In the case of the @for block, feature wise they serve the same purpse with a few advantages : 1) No need to import the directive in standalone components. The @for syntax is automatically included in templates, no explicit imports are needed. 2) The @for now forces developers to use a tracking function, so performance-wise it's safer 3) If the collection is empty, you can use the @empty block to display something specific. 4) Generate a bit less code in the final bundle
401 | | 104 | @if vs *nglf ?
1) No need to import the directive in standalone components. The @if syntax is automatically included in templates, no explicit imports are needed. 2) @if supports @else if and @else conditions. esle if is not supported by *nglf 3) Generate a bit less code in the final bundle
402 | | 105 | Migrate control flow to new angular version ?
Control flow syntax is available from Angular v17. The new syntax is baked into the template, so you don't need to import CommonModule anymore. This schematic migrates all existing code in your application to use new Control Flow Syntax. Run the schematic using the following command: `ng generate @angular/core:control-flow`
403 |
404 | | No. | Questions |
405 | | --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
406 | | 106 | What is a CORS error, why does it arise, and how do you fix it?
CORS stands for Cross-Origin Resource Sharing—a security feature built into browsers. It blocks requests made from one origin (domain, protocol, or port) to another origin unless explicitly allowed by the server.
407 | For example:
408 | - Your frontend is hosted at `frontend.com`.
409 | - Your backend API is hosted at `api.backend.com`.
410 | The browser treats these as different origins and blocks the request unless it’s explicitly allowed. When the backend server doesn’t include the right CORS headers, the browser refuses to share the response and throws this error: > *Access to fetch at 'https://api.backend.com' from origin 'https://frontend.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present.*
411 | In short, the browser isn’t blocking the request—it’s blocking the response for security reasons.
412 | It’s not a frontend issue. It’s a server-side configuration issue.
413 |
414 | Solution
415 | -----------------------------------------------------
416 | Step 1: Update the Backend.
417 | The server must send the right headers, like:
418 | - `Access-Control-Allow-Origin: *` (Allows all origins).
419 | - Or specify trusted domains like `Access-Control-Allow-Origin: https://frontend.com`.
420 |
421 | Step 2: Handle Preflight Requests (OPTIONS).
422 | For complex requests (like `POST` with custom headers), browsers send a preflight request before the actual call.
423 |
424 | The server must respond to this with:
425 | - `Access-Control-Allow-Methods: GET, POST, OPTIONS`
426 | - `Access-Control-Allow-Headers: Content-Type, Authorization`
427 |
428 | Step 3: Use a Proxy for Local Development.
429 | If the backend isn’t updated yet, set up a proxy to forward requests through the same origin as your frontend.
430 |
431 | Can We Bypass CORS?
432 | -----------------------------------------------------
433 | Short answer—No. Any hacky workaround, like disabling CORS in the browser or using extensions, won’t work in production. Fix it properly by configuring the server. That’s the only scalable solution.
434 |
435 |
--------------------------------------------------------------------------------
/Rxjs/Pluck.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/piyalidas10/Angular-Interview-Questions/b380d11e17593487b51648a068b18011f5f527ed/Rxjs/Pluck.pdf
--------------------------------------------------------------------------------
/Rxjs/RxJS Operators by Eating a Pizza_ zip, forkJoin, & combineLatest Explained with Examples.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/piyalidas10/Angular-Interview-Questions/b380d11e17593487b51648a068b18011f5f527ed/Rxjs/RxJS Operators by Eating a Pizza_ zip, forkJoin, & combineLatest Explained with Examples.pdf
--------------------------------------------------------------------------------
/Rxjs/Rxjs Operators.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/piyalidas10/Angular-Interview-Questions/b380d11e17593487b51648a068b18011f5f527ed/Rxjs/Rxjs Operators.pdf
--------------------------------------------------------------------------------
/Rxjs/TAP operator.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/piyalidas10/Angular-Interview-Questions/b380d11e17593487b51648a068b18011f5f527ed/Rxjs/TAP operator.pdf
--------------------------------------------------------------------------------
/Rxjs/concatMap.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/piyalidas10/Angular-Interview-Questions/b380d11e17593487b51648a068b18011f5f527ed/Rxjs/concatMap.pdf
--------------------------------------------------------------------------------
/Rxjs/readme.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Rxjs/rxjs-error-handling.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/piyalidas10/Angular-Interview-Questions/b380d11e17593487b51648a068b18011f5f527ed/Rxjs/rxjs-error-handling.pdf
--------------------------------------------------------------------------------
/Rxjs/rxjs-higher-order-mapping.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/piyalidas10/Angular-Interview-Questions/b380d11e17593487b51648a068b18011f5f527ed/Rxjs/rxjs-higher-order-mapping.pdf
--------------------------------------------------------------------------------
/Tree_Shaking_after.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/piyalidas10/Angular-Interview-Questions/b380d11e17593487b51648a068b18011f5f527ed/Tree_Shaking_after.png
--------------------------------------------------------------------------------
/Tree_Shaking_before.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/piyalidas10/Angular-Interview-Questions/b380d11e17593487b51648a068b18011f5f527ed/Tree_Shaking_before.png
--------------------------------------------------------------------------------
/Typescript_Jumpstart_Book_Udemy.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/piyalidas10/Angular-Interview-Questions/b380d11e17593487b51648a068b18011f5f527ed/Typescript_Jumpstart_Book_Udemy.pdf
--------------------------------------------------------------------------------
/feature_module.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/piyalidas10/Angular-Interview-Questions/b380d11e17593487b51648a068b18011f5f527ed/feature_module.png
--------------------------------------------------------------------------------