accordion test

Angular is a most popular web development framework for developing mobile apps as well as desktop applications.

Angular framework is also utilized in the cross platform mobile development called IONIC and so it is not limited to web apps only.

Angular is an open source framework written and maintained by angular team at Google and the Father of Angular is Misko Hevery.

By Angular docs - “Angular is a platform that makes it easy to build applications with the web. Angular combines declarative templates, dependency injection, end to end tooling, and integrated best practices to solve development challenges. Angular empowers developers to build applications that live on the web, mobile, or the desktop”

Angular is focusing on data-binding, extensible HTML and on application test-ability but it is still in design and prototyping stage.

Stayed Informed - What Is Angular 4 or 5 or 6 or 7 or 8?

Angular framework helps us to build client applications in HTML and JavaScript. Angular 2 is so simpler, faster, modular and instrumented design.

Angular 2 targeting to modern browsers and it is developing using ES6 (ES6 is called ECMAScript version 6). It also support to ECMAScript version 5(ES5).

You don’t worry about the versions of ECMAScript. The ES6 compiler manages to the versioning related problems.

All the Angular 2 framework code is already being written in ECMAScript 6.

The set of supporting modern browsers are :
1. Chrome
2. Firefox
3. Opera
4. Safari
5. IE Version10, 11 and so on...

On mobiles, it is supporting to the list of Chrome on Android, iOS 6+, Windows Phone 8+ and Fire-Fox mobile and also trying to support to older versions of Android.

Angular 2 team working with Traceur compiler team to provide the support to build some extensions. This set of extensions called “ES 6 +A”.

The “Angular 2” is using “Traceur” compiler. Traceur is a compiler that takes “ES6” and compiles it down (ES5) to regular JavaScript that runs in your browsers. It is run everywhere you want to do.

Angular 2 is a most popular framework for developing mobile apps. It is also for desktop as well mobile applications.

The Angular 2 is focusing on data-binding, extensible HTML and on application test-ability but it is still in design and prototyping stage.

Angular framework helps us to build client applications in HTML and JavaScript.
Angular 2 is so simpler, faster, modular and instrumented design.

Angular 2 targeting to modern browsers and it is developing using ES6 (The ES6 is called ECMAScript version 6). It also support to ECMAScript version 5(ES5).

You don’t worry about the versions of ECMAScript. The compiler manages to the versioning related problems.

All Angular 2 framework code is already being written in ECMAScript 6.

The Angular 2 architecture diagram identifies the eight main building blocks as.

1. Module
2. Component
3. Template
4. Outpouts
5. Data Binding
6. Directive
7. Service
8. Dependency Injection

The Angular 2 framework consists of several libraries, the some of them working as core and some are optional.

Advantages of Angular 2

1. The Angular 2 has better performance.
2. The Angular 2 has more powerful template system.
3. The Angular 2 provide simpler APIs, lazy loading and easier to application debugging.
4. The Angular 2 much more testable.
5. The Angular 2 provides to nested level components.
6. The Angular 2 execute run more than two programs at the same time.

The ECMAScript is a scripting language which is developed by Ecma International Org.
Currently ECMAScript available in multiple versions that are ES5 and ES6 and both of versions fully supported to Chrome, Firefox, Opera, Safari, and IE etc.

The Traceur is a JavaScript compiler. The Traceur compiler is very popular now days use to allow use to use the features from the future. This compiler is fully supported to ES5, ES6 and also to vNext. The main goal of Traceur compiler is to inform to design of new JavaScript features and wrote the programming code of new efficient and good manners.

The New Features of Angular 2 :

1. Angular 2 is Entirely Component Based
2. Directives
3. Dependency Injection
4. Used of TypeScript
5. Used of Lambdas or Arrow functions
6. Generics
7. Forms and Validations
8. And So on.....

Component Based - It is entirely component based. It is not used to scope and controllers and Angular 2 are fully replaced by components and directives.

Directives - The directive can be declared as @Directive annotation.
A component is a directive with a template and the @Component decorator is actually a @Directive decorator extended with template oriented features.

Dependency Injection - Dependency Injection is a powerful pattern for managing code dependencies. There are more opportunities for component and object based to improve the dependency injection.

Use of TypeScript - Type represents the different types of values which are using in the programming languages and it checks the validity of the supplied values before they are manipulated by your programs.

Generics- TypeScript has generics which can be used in the front-end development.

Lambdas and Arrow functions – In the TypeScript, lambdas/ arrow functions are available. The arrow function is additional feature in typescript and it is also known as a lambda function.

Forms and Validations - Angular 2 forms and validations are an important aspect of front-end development.


Why You Used Angular 2?

1. It is entirely component based.
2. Better change detection
3. Angular2 has better performance.
4. Angular2 has more powerful template system.
5. Angular2 provide simpler APIs, lazy loading and easier to application debugging.
6. Angular2 much more testable
7. Angular2 provides to nested level components.
8. Ahead of Time compilation (AOT) improves rendering speed
9. Angular2 execute run more than two programs at the same time.
10.Angular1 is controllers and $scope based but Angular2 is component based.
11.The Angular2 structural directives syntax is changed like ng-repeat is replaced with *ngFor etc.
12.In Angular2, local variables are defined using prefix (#) hash. You can see the below *ngFor loop Example.
13.TypeScript can be used for developing Angular 2 applications
14.Better syntax and application structure

The core differences and many more advantages on Angular 2 vs. Angular 1 as following :

1. It is entirely component based.
2. Better change detection
3. Angular2 has better performance.
4. Angular2 has more powerful template system.
5. Angular2 provide simpler APIs, lazy loading and easier to application debugging.
6. Angular2 much more testable
7. Angular2 provides to nested level components.
8. Ahead of Time compilation (AOT) improves rendering speed
9. Angular2 execute run more than two programs at the same time.
10.Angular1 is controllers and $scope based but Angular2 is component based.
11.The Angular2 structural directives syntax is changed like ng-repeat is replaced with *ngFor etc.
12.In Angular2, local variables are defined using prefix (#) hash. You can see the below *ngFor loop Example.
13.TypeScript can be used for developing Angular 2 applications
14.Better syntax and application structure


There are more advantages over performance, template system, application debugging, testing, components and nested level components.


For Examples as,
Angular 1 Controller:-
var app = angular.module("userApp", []);
   app.controller("productController", function($scope) {
   $scope.users = [{ name: "Anil Singh", Age:30, department :"IT" },
  { name: "Aradhya Singh", Age:3, department :"MGMT" }];
}); 

Angular 2 Components using TypeScript:-

Here the @Component annotation is used to add the metadata to the class.

import { Component } from 'angular2/core';
@Component({
  selector: 'usersdata',
  template: `

{{users.name}}

` }) export class UsersComponent { users = [{ name: "Anil Singh", Age:30, department :"IT" }, { name: "Aradhya Singh", Age:3, department :"MGMT" }]; }

Bootstrapping in Angular 1 using ng-app,
angular.element(document).ready(function() {
   angular.bootstrap(document, ['userApp']);
});

Bootstrapping in Angular 2,
import { bootstrap } from 'angular2/platform/browser';
import { UsersComponent } from './product.component';

bootstrap(UserComponent);

The Angular2 structural directives syntax is changed like ng-repeat is replaced with *ngFor etc.

For example as,
//Angular 1,
Name: {{user.name}}, Age : {{user.Age}}, Dept: {{user.Department}}
//Angular2,
Name: {{user.name}}, Age : {{user.Age}}, Dept: {{user.Department}}

Follow the below steps to Setup Angular 2 in Visual Studio -

Note - In the below steps, Viainda is a user in my machine. So that your end, you will see you or your user in your machine.

Steps 1- C:\Users\Viainda>
Steps 2- C:\Users\Viainda>F:
Steps 3- F:\>
Steps 4- F:\>mkdir Ng2DemoApp
Steps 5- F:\>cd Ng2DemoApp
Steps 6- F:\Ng2DemoApp>node --version
Steps 7- F:\Ng2DemoApp>dotnet new --install Microsoft.AspNetCore.SpaTemplates::*
Steps 8- F:\Ng2DemoApp>
Steps 9- F:\Ng2DemoApp>dotnet new angular
Steps 10- F:\Ng2DemoApp>dir
Steps 11- F:\Ng2DemoApp>dotnet restore
Steps 12- F:\Ng2DemoApp>npm install
Steps 13- F:\Ng2DemoApp>start Ng2DemoApp.csproj
Steps 14- After press F5 key on project to displays on your browser with “Hello, world!”.

Reference - Click for more detail...

The Type represents the different types of values which are using in the programming languages and it checks the validity of the supplied values before they are manipulated by your programs.

The TypeScript provides data types as a part of its optional type and its provide us some primitive types as well as a dynamic type “any” and this “any” work like “dynamic”.

In TypeScript, we define a variable with a “type” and appending the “variable name” with “colon” followed by the type name i.e.

let isActive: boolean = false; OR var isActive: boolean = false;
let decimal: number = 6; OR var decimal: number = 6;
let hex: number = 0xf00d; OR var hex: number = 0xf00d;
let name: string = "Anil Singh"; OR var name: string = "Anil Singh";
let binary: number = 0b1010; OR var binary: number = 0b1010;
let octal: number = 0o744; OR var octal: number = 0o744;
let numlist: number[] = [1, 2, 3]; OR var numlist: number[] = [1, 2, 3];
let arrlist: Array = [1, 2, 3]; OR var arrlist: Array = [1, 2, 3];

#Any Keyword
let list: any[] = [1, true, "free"];
list[1] = 100;

#Any Keyword
let notSureType: any = 10;
notSureType = "maybe a string instead";

notSureType = false; // definitely a Boolean

Number : the “number” is a primitive number type in TypeScript. There is no different type for float or double in TypeScript.
Boolean : The “boolean” type represents true or false condition.
String : The “string” represents sequence of characters similar to C#.
Null : The “null” is a special type which assigns null value to a variable.
Undefined : The “undefined” is also a special type and can be assigned to any variable.
Any : this data type is the super type of all types in TypeScript. It is also known as dynamic type and using “any” type is equivalent to opting out of type checking for a variable.

A note about “let” keyword –

You may have noticed that, I am using the “let” keyword instead of “var” keyword. The “let” keyword is actually a newer JavaScript construct that TypeScript makes available. Actually, many common problems in JavaScript are reducing by using “let” keyword. So we should use “let” keyword instead of “var” keyword.


For more Questions on TypeScript, explore this link...

AOT compilation stands for “Ahead of Time compilation” and it are used to compiles the angular components and templates to native JavaScript and HTML during the build time instead of run-time. The compiled HTML and JavaScript are deployed to the web server so that the compilation and render time can be saved by the browser. It is the big advantage to improve the performance of applications.

Advantages of AOT -

1. Faster download: - The Angular 2 app is already compiled so it is faster.
2. Faster Rendering: - If the app is not AOT compiled and the compilation process happens in the browser once the application is fully loaded. This has a wait time for all necessary components to be downloaded and then the time taken by the compiler to compile the app. With AOT compilation, this is optimized.
3. Lesser Http Requests: - It is supporting to the lazy loading. Actually, lazy loading is great concepts for sending HTTP request to the server. It is minimise the multiple requests for each associated html and css, there is a separate request goes to the server.
4. Detect error at build time: - In Angular 2, the compilation happens beforehand and most of the errors can be detected at the compile time and this process providing us a better application’s stability.

Disadvantages of AOT -
1. AOT only works only with HTML and CSS and not for other file types. If required other file types that time we will need to follow the previous build step.
2. We need to maintain AOT version of bootstrap file.
3. We need to clean-up step before compiling.

Lazy Loading - enables us to load only the module user is interacting and keep the rest to be loaded at run-time on demand.

Lazy Loading speeds up the application initial load time by splitting the code into multiple bundles and loading them on demand.

1. Each and every Angular2 application must have one main module that is called “AppModule” and your code should be splitted into various child modules based on your applications.
2. We do not require to import or declare lazily loading module in root module.
3. Add the route to top level routing and takes routes array and configures the router.
4. Import module specific routing in the child module.
5. And so on.

The optimizations are depends on the size of applications, type and other factors but normally we consider following optimizing points i.e.

1. Consider AOT compilation.
2. Consider lazy loading instead of fully bundled app if the app size is more.
3. Keep in mind, your application is bundled and disfeatured.
4. Keep in mind, your application doesn’t have un-necessary import statements.
5. Keep in mind, your application’s 3rd party unused library. If exist and not used, removed from your application.
6. Remove your application dependencies if not required.


What are the Securities Threats should we be Aware of in Angular 2 Applications?

As like your other web applications, you should flow in angular 2 applications also.

There are some basic guidelines to mitigate the security risks.

1. Consider using AOT compilation.
2. Try to avoid using or injecting dynamic HTML content to your component.
3. Try to avoid using external URLs if not trusted.
4. Try to prevent XSRF attack by restricting the REST APIs.

If you are using external resources like HTML, CSS, which is coming from outside the application in case you follow best practice/cleanly your apps.


Angular 1 and Angular 2 Integration

1. Angular frameworks provide the support of mixing code of Angular 1 and Angular 2 in the same application.
2. We can write the mixing components of Angular 1 and Angular 2 in the same view.
3. We can inject services across frameworks of Angular 1 and Angular 2 in the same application.
4. Both Angular 1's and Angular 2's data binding works across frameworks in the same view.

Angular 2 Constructors:-

1. The constructor is a default method runs when component is being constructed.
2. The constructor is a typescript feature and it is used only for a class instantiations and nothing to do with Angular 2.
3. The constructor called first time before the ngOnInit().


Angular 2 ngOnInit:-

1. The ngOnInit event is an Angular 2 life-cycle event method that is called after the first ngOnChanges and the ngOnInit method is use to parameters defined with @Input otherwise the constructor is OK.
2. The ngOnInit is called after the constructor and ngOnInit is called after the first ngOnChanges.
3. The ngOnChanges is called when an input or output binding value changes.


Example as,
import {Component, OnInit} from '@angular/core';

export class App implements OnInit{
  constructor(){
  }

  ngOnInit(){
  }
}

In Angular 1.x, ngInit is called when template is re-rendered. In other words “ng-init” is called, when I take turns back to a page.

In Angular2, there is no “ng-init” but we can create a ways like this using the directive and ngOnInit class. Angular 2 provides life cycle hook ngOnInit by default.


The ngOnInit is invoked when the component is initialized and invoked only once when the directive is instantiated. It is a best practice to implement these life-cycle interfaces.

According to Angular2 Doc, “The ngOnInit is called right after the directive's data-bound properties have been checked for the first time, and before any of its children have been checked. It is invoked only once when the directive is instantiated.”


For example as,
import { Directive, Input } from '@angular/core';

@Directive({
  selector: '[ngInit]'
})

class NgInit {
  @Input() ngInit;

  ngOnInit() {
    if(this.ngInit) { this.ngInit(); }
  }
}

In template as following,
< div *ngIf="Timer.dateTime === currentDateTime" >
    < div *ngIf="Timer.checked" [ngInit]="Start" >< / div >
    < div *ngIf="!Timer.checked" [ngInit]="Stop" >< / div >
< / div >

Angular 2 Complete lifecycle hook interface inventory:-

1. ngOnChanges - called when an input binding value changes.
2. ngOnInit - after the first ngOnChanges.
3. ngDoCheck - after every run of change detection.
4. ngAfterContentInit - after component content initialized.
5. ngAfterContentChecked - after every check of component content.
6. ngAfterViewInit - after component's view(s) are initialized.
7. ngAfterViewChecked - after every check of a component's view(s).
8. ngOnDestroy - just before the component is destroyed.


Angular 2 Lifecycle Events Log:-

1. onChanges
2. onInit
3. doCheck
4. afterContentInit
5. afterContentChecked
6. afterViewInit
7. afterViewChecked
8. doCheck
9. afterContentChecked
10.afterViewChecked
11.onChanges
12.doCheck
13.afterContentChecked
14.afterViewChecked
15.onDestroy


Angular 2 Constructors:-
The constructor is a default method runs when component is being constructed.
The constructor is a typescript feature and it is used only for a class instantiations and nothing to do with Angular 2.
The constructor called first time before the ngOnInit().

Example as,
import {Component} from 'angular2/core';
import {UserService} from './userService';

@Component({
  selector: ‘list-user’,
  template: `< ul >< li *ngFor="#user of users">{{user.name}}< / ul >`
})

class App_Component {
  users:Array;
  constructor(private _userService: UserService) {
      this.users = _userService.getUsers();
  }
}

Angular 2 ngOnInit and ngOnChanges:-

The ngOnInit event is an Angular 2 life-cycle event method that is called after the first ngOnChanges and the ngOnInit method is use to parameters defined with @Input otherwise the constructor is OK.

The ngOnInit is called after the constructor and ngOnInit is called after the first ngOnChanges.

The ngOnChanges is called when an input or output binding value changes.


Examples as,
import {Component, OnInit} from '@angular/core';
export class App implements OnInit{
  constructor(){
  }

  ngOnInit(){
  }
}

Angular 2 ngOnDestroy :-

The ngDestroy directive is called in a component lifecycle just before the instance of the component is finally destroyed.

Example as,
@Directive({
    selector: '[destroyDirective]'
})
export class OnDestroyDirective implements OnDestroy {

  //Call Constructor and set hello Msg.
  constructor() {
    this.helloMsg = window.setInterval(() => alert('Hello, I am Anil'), 2000);
  }

  //Destroy to the component
  ngOnDestroy() {
     window.clearInterval(this.helloMsg);
  }
}

Angular 4 contains some additional Enhancement and Improvement. Consider the following enhancements.

1. Smaller & Faster Apps
2. View Engine Size Reduce
3. Animation Package
4. NgIf and ngFor Improvement
5. Template
6. NgIf with Else
7. Use of AS keyword
8. Pipes
9. HTTP Request Simplified
10.Apps Testing Simplified
11.Introduce Meta Tags
12.Added some Forms Validators Attributes
13.Added Compare Select Options
14.Enhancement in Router
15.Added Optional Parameter
16.Improvement Internationalization

Explore in detial with examples..

The Angular 5 Contains bunch of new features, performance improvements and lot of bug fixes and also some surprises to Angular lovers.

1. Make AOT the default
2. Watch mode
3. Type checking in templates
4. More flexible metadata
5. Remove *.ngfactory.ts files
6. Better error messages
7. Smooth upgrades
8. Tree-Shakeable components
9. Hybrid Upgrade Application
10.And so on...

Angular 5 Performance Improvements -

1. Use of addEventListener for the faster rendering and it is the core functionality.
2. Update to new version of build-optimizer.
3. Added some Improvements on the abstract class methods and interfaces
4. Remove decorator DSL which depends on Reflect for Improve the Performance of Apps and This is the core functionality.
5. Added an option to remove blank text nodes from compiled templates
6. Switch Angular to use Static-Injector instead of Reflective-Injector.
7. Improve the applications testing.
8. Improve the performance of hybrid applications
9. Improvements on Lazy loading for Angular
10.And so on...

Explore in detial with examples..
Off-course! Angular 6 being smaller, faster and easier to use and it will making developers life easier. Recently Angular 6.0.0-beta.7 is released and production release on end of March 2018.

The Angular Team are working on lots of bug fixes, new features and added/update/remove/ re-introduce/ and may more things.

Let’s start to explore all changes of Angular 6 step by step!

Added ng update - This CLI commands will update your angular project dependencies to their latest versions. The ng update is normal package manager tools to identify and update other dependencies.

# ng update

Angular 6 uses RxJS 6 - this is the third-party library (RxJS) and introduces two important changes as compared to RxJS 5.
1. RxJS 6 introduces a new internal package structure
2. Operator concept

Both are requires you to update your existing code

To update to RxJS 6, you simply run -

# npm install --save rxjs@6
Explore in detial with examples..

Angular 7 being smaller, faster and easier to use and it will making developers life easier. Now Angular 7 is released! This is a major release and expanding to the entire platform including -

1. Core framework
2. Angular Material
3. CLI

Let’s introduce added and modified new features of Angular 7 -

1. Added a new interface - UrlSegment[] to CanLoad interface
2. Added a new interface - DoBootstrap interface
3. Angular 7 added a new compiler - Compatibility Compiler (ngcc)
4. Introduce a new Pipe called - KeyValuePipe
5. Angular 7 now supporting to TypeScript 2.9 and Added Virtual Scrolling and Drag & Drop
6. Added a new elements features - enable Shadow DOM v1 and slots
7. Added a new router features - warn if navigation triggered outside Angular zone
8. Added a new mappings for ngfactory and ngsummary files to their module names in AOT summary resolver.
9. Added a new "original" placeholder value on extracted XMB
10.Added a new ability to recover from malformed URLs
11.Added a new compiler support dot (.) in import statements and also avoid a crash in ngc-wrapped
12.Update compiler to flatten nested template fns

Angular 7 added a new compiler that is called Angular Compatibility Compiler (ngcc).

The ngcc Angular node_module compatibility compiler - The ngcc is a tool which "upgrades" node_module compiled with non-ivy ngc into ivy compliant format.

This compiler will convert node_modules compiled with Angular Compatibility Compiler (ngcc), into node_modules which appear to have been compiled with TSC compiler transformer (ngtsc) and this compiler conversions will allow such “legacy” packages to be used by the Ivy rendering engine.

TSC transformer which removes and converts @Pipe, @Component, @Directive and @NgModule to the corresponding definePipe, defineComponent, defineDirective and defineInjector.


UrlSegment Interface -

UrlSegment interface represents a single URL segment and the constructor, properties, and methods look like below UrlSegment class i.e.

classUrlSegment {
constructor(path: string, parameters: {...})
 path: string
 parameters: {...}
 toString(): string
}
Explore in detial with examples..

Angular 8 being smaller, faster and easier to use and it will making Angular developers life easier. Angular version numbers have three parts: major.minor.patch. This release contains the following added and Improvements over the entire Angular platform including:-

=> Added Support for TypeScript 3.2

=> Added a Navigation Type Available during Navigation in the Router

=> Added pathParamsOrQueryParamsChange mode for runGuardsAndResolvers in the Router

=> Allow passing state to routerLink Directives in the Router

=> Allow passing state to NavigationExtras in the Router

=> Restore whole object when navigating back to a page managed by Angular Router

=> Added support for SASS

=> Resolve generated Sass/Less files to .css inputs

=> Added Predicate function mode for runGuardsAndResolvers:-
This option means guards and resolvers will ignore changes when a provided predicate function returns `false`. This supports use cases where an application needs to ignore some param updates but not others.

For example, changing a sort param in the URL might need to be ignored, whereas changing the `project` param might require re-run of guards and resolvers.

=> Added functionality to mark a control and its descendant controls as touched: - add markAllAsTouched () to AbstractControl

=> Added ng-new command that builds the project with Bazel

=> Use image based cache for windows BuildKite

=> Export NumberValueAccessor & RangeValueAccessor directives

=> Use shared DomElementSchemaRegistry instance for improve performance of platform-server (@angular/platform-server):-
Right now the ServerRendererFactory2` creates a new instance of the `DomElementSchemaRegistry` for each and every request, which is quite costly (for the Tour of Heroes SSR example this takes around **15%** of the overall execution time)

=> In the Compiler-CLI, expose ngtsc as a TscPlugin

=> Now the Performance Improvements on core, more consistent about “typeof checks”

=> Restore whole object when navigating back to a page managed by Angular Router

Explore in detial with examples..


ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.
^