Instead of importing these common modules and components in every feature module, you can create a shared module that has all these modules and components. Import them into a shared module and import this shared module into all feature modules. This will save imports and a lot of coding lines.
Promise vs Observable:
a Promise is eager, whereas an Observable is lazy,
a Promise is always asynchronous, while an Observable can be either synchronous or asynchronous,
a Promise can provide a single value, whereas an Observable is a stream of values (from 0 to multiple values),
you can apply RxJS operators to an Observable to get a new tailored stream.
ReactiveForm – formgroup, formcontrol,
formarray are the classes available in angular forms package.
Formcontrol – every html form elements is
an formcontrol. Using formcontrol we can specify the input elements.
Formgroups – collection of form controls
is called formgroup.
FormArray – collection of form groups.
Reactive & template driven are the ways
to create a form.
RXJS - Observable vs Subscribe
In observable you need to define a function for publishing values. Observable are triggered as soon as you subscribe it.
Like Observable subject can't be consumed by subscribe it. while subscribe it just registering instance. Subject actually called by calling next method. Basically subject controlling the trigger action. Subject are used inside the service. Whenever data change happened in one component that need to be known in other component.
Services: We can write business logic in service file and inject in required component or module level. Service file need to specify in providers. Providers will create the new instance for the service class. Specifying the service in module provider, then service instance scope is across module level.
Angular Versions:
Angular 7:
It is released with performance improvements and some interesting features like CLI Prompts, Virtual Scrolling, and Drag and Drops.Google has released Angular version 7 in Oct 2018 with a lot of optimum features and significant changes like Angular Material, CLI prompts, Scrolling, Drag, and Virtual and Drop & Component Dev Kit (CDK)
CLI prompts
In Angular 7, the command-line interface (CLI) prompts have been updated to v7.0.2, When the user executes common commands like ng add @angular/material or ng new it will automatically prompt users commands like ng add @angular/material help you discover built-in features like routing or SCSS support.
Angular 7 added a new compiler called the Angular Compatibility Compiler (ngcc). Just like the name suggests, the angular compiler offers an 8-phase rotating ahead-of-time compilation(AOT) and most of the angular applications noticed a massive reduction (95-99%) in bundle sizes.
Angular Material CDK (Component Dev Kit)
- Virtual scrolling
The scrolling package enables loads and unloads items from the DOM depending upon visible parts of lists, resulting into a much faster experience for users having huge scrollable lists.
- Drag & drop
Now you can re-order the list just by dragging and dropping with new @angular/cdk/drag-drop module which provides free dragging, sorting within a list, transferring items between lists, animations and much more.
Application performance
Many developers include the reflect-metadata polyfill in the production, so they decided to fix this part by automatically removing it from your polyfills.ts file and to speed up the performance new applications will warn when the initial bundle is more than 2MB and will error at 5MB which user can modify it in angular.json file.
Angular Do-Bootstrap
Angular 7 added a new life-cycle hook (ngDoBootstrap) and interface (DoBootstrap), It's used for bootstrapping modules that need to bootstrap a component.
Router
In Angular 7, If you try to trigger navigation outside of the Angular zone it logs a warning (only in development mode). Also, adds navigation execution context info to activation hooks.
Some Major updates in Angular 7
- Angular 7 now supporting to TypeScript 3.1
- Added a new ability to recover from malformed URLs
- Downloadable console for starting and running Angular projects on your local machine
- compiler-cli: update tsickle to 0.29.x
- Export defaultKeyValueDiffers to private API
1. Angular 7 Released on October 2018
2. This is a major release and expanding to the entire platform including-
— Core framework,
— Angular Material,
— CLI
3. Added a new interface - UrlSegment[] to CanLoad interface
4. Added a new interface - DoBootstrap interface
5. Angular 7 added a new compiler - Compatibility Compiler (ngcc)
6. Introduce a new Pipe called - KeyValuePipe
7. Angular 7 now supporting to TypeScript 3.1
8. Added Virtual Scrolling features
9. Added Drag & Drop features
10. Added Better Error Handling
11. Added a new elements features - enable Shadow DOM v1 and slots
12. Added a new router features - warn if navigation triggered outside Angular zone
13. Added a new mapping for ngfactory and ngsummary files to their module names in AOT summary resolver.
14. Added a new "original" placeholder value on extracted XMB
15. Added a new ability to recover from malformed URLs
16. Added a new compiler support dot (.) in import statements and also avoid a crash in ngc-wrapped
17. Update compiler to flatten nested template fns
18. Added Native Script
19. Added Bundle Budget.
Angular 8
Angular 8 has introduced with a bunch of workflow and performance improvements and a lot has changed in the framework under the hood in terms of tooling. Comparing Angular 6 vs Angular 7 vs Angular 8 Finally, Angular 8 released with ivy rendering which Angular team was along with updated angular core framework, Angular Material, and the Command Line Interface or CLI.
Ivy Engine
Ivy is a major part of this release, and it took most of the effort from Angular 6 to release it. Ivy is a new rendering engine that will produce smaller bundle sizes But it's not recommended to start using it in production not just yet. Know more about what is ivy?
Web Workers
Web workers are essential for improving the parallelizability and the speed of your application. Angular 8.0 added support to CLI which provides one bundle for every web worker & they do it by writing code off the main thread.
Lazy Loading
Lazy loading is based on the concepts of Angular Routing and Angular 8 added support for dynamic EcmaScript imports in router configuration as it helps bring down the size of large files by lazily loading the files that are required.
Angular Firebase
Angular 8 officially added support for firebase and now deploying an Angular app to Firebase is very easy, and it doesn’t take too much time using Angular CLI, Service Worker.
Differential loading
Your Angular 8 apps now will more performant thanks to differential loading and two bundles are created for a production build i,e bundle for new browser with ES2015+ and with an old browser with ES5 version. The correct bundle will automatically load by the browser with new ES6 modules present in the new browser.
The ng build command with the --prod flag will take care of bundling everything out of the box.
Opt-In Usage Sharing
With Angular 8, we can switch between IVY and the regular View engine build. It enables opt-in to sharing telemetry about your Angular CLI usage with the Angular and can collect data like commands used and the build speed if users allow them which will help developers improve in the future.
Angular CLI Builders
The CLI Builder API is stable and available to developers who want to customize the Angular CLI by adding or modifying commands.
Major features included in Angular 8
- AngularJS API Migration Improvements with $location service
- Updated Typescript to 3.4.x
- @angular/platform-webworker and@angular/platform-webworker-dynamic both the packages are deprecated
- @angular/http removed from the list of packages
- ng-build, ng-test, and ng-run are equipped to be extended by 3rd-party libraries and tool.
- Angular router backward compatibility
- Dart-sass for Sass files
- The
ViewChild and ContentChild decorators now must have a new option called static.
- Multicasting
Multicasting is the practice of broadcasting to a list of multiple subscribers in a single execution. With a multicasting observable, you don't register multiple listeners on the document, but instead re-use the first listener and send values out to each subscriber.
Bootstrap:
A bootstrapped component is an entry component that Angular loads into the DOM during the bootstrap process (application launch). Other entry components are loaded dynamically by other means, such as with the router.
Ahead-of-Time (AoT) Compilation
An Angular application consists mainly of components and their HTML templates. Because the components and templates provided by Angular cannot be understood by the browser directly, Angular applications require a compilation process before they can run in a browser.
The Angular Ahead-of-Time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase before the browser downloads and runs that code. Compiling your application during the build process provides a faster rendering in the browser.
Angular compilation
In Angular, there are two ways to compile your application:
- Just-in-Time (JIT), which compiles your app in the browser at runtime.
- Ahead-of-Time (AOT), which compiles your app at build time.
JIT compilation is the default when you run the ng build (build only) or ng serve (build and serve locally) CLI commands:
For AOT compilation, include the --aot option with the ng build or ng serve command:
The ng build command with the --prod meta-flag (ng build --prod) compiles with AOT by default.
Why compile with AOT?
With AOT, the browser downloads a pre-compiled version of the application. The browser loads executable code so it can render the application immediately, without waiting to compile the app first.
- Fewer asynchronous requests
The compiler inlines external HTML templates and CSS style sheets within the application JavaScript, eliminating separate ajax requests for those source files.
- Smaller Angular framework download size
There's no need to download the Angular compiler if the app is already compiled. The compiler is roughly half of Angular itself, so omitting it dramatically reduces the application payload.
- Detect template errors earlier
The AOT compiler detects and reports template binding errors during the build step before users can see them.
AOT compiles HTML templates and components into JavaScript files long before they are served to the client. With no templates to read and no risky client-side HTML or JavaScript evaluation, there are fewer opportunities for injection attacks