1. Angular2 performance
Be default, Angular2 performance will be good. Still you can improve the angular2 performance of your application using following ways
i. Use HTTP/2 to load assets parallel from server which increases performance up to 30-50%.
ii. Reference: http://www.zackarychapple.guru/angular2/2016/05/31/tour-of-heroes-http2.html
B. Use gulp-inline-ng2-template
ii. Reference: https://github.com/angular/angular/issues/4328
2. Angular 1.3 vs 2
A. Angular2 written in Typescript and meets the ECMASCRIPT 6 specifications.
B. Angular2 is entirely component based. Controllers and $scope no longer used. Components are directives with a template.
C. Form validations are easier in angular2
D. Angular2 support for native mobile – iOS and Android
E. Angular2 support for server side rendering. Angular2 provides more choices of languages. You can use any of the language from ES5, ES6, TypeScript or Dart to write Angular 2 code.
F. Improved testability in angular2.
G. Support to migrate from angular1.x to 2 using ng-upgrade.
Apart from Angular2 features like performance, mobility, testability etc. We can see the major differences in syntaxes for angular 1.x and angular 2 versions. Few major changes are listed below.
|Not built with mobile support||Built with mobile support|
|Easy to setup and Difficult to create directives, controller files manually.||Simple to setup and use it using angular-cli|
|Controllers and scope to maintain logic||Components with minimal syntax|
|Bootstrapping using ng-app||Made a simpler bootstrap|
|Structural directives like ng-repeat, ng-if been changed.||*ngFor, *ngIf syntax changed.|
|You cannot use HTML DOM element properties and events in angular 1.x. Instead we have to use ng-href, ng-src, ng-show etc.||You can use directly HTML DOM element properties and events in angular2.|
|Services are defined in 5 ways like factory, service, provider, constant and values||We will use Injectable here|
|$scope plays major role here which could be harmful in some ways.||No scope in angular2.|
|Dependency Injection achieve via controllers||DI achieves via constructor in classes|
|Form validations are difficult to apply||Its very easy with in-built syntaxes.|
|No Server Side Rendering||Server Side Rendering is possible|
3. how to Upgrade from angular 1.3 to angular2
Here is an example of what an Angular 1 project upgrade to Angular 2 may look like.
- Include the Angular 2 and ng-upgrade libraries with your existing application
- Pick a component which you would like to migrate
- Edit an Angular 1 directive’s template to conform to Angular 2 syntax
- Convert the directive’s controller/linking function into Angular 2 syntax/semantics
- Use ng-upgrade to export the directive (now a Component) as an Angular 1 component (this is needed if you wish to call the new Angular 2 component from an Angular 1 template)
- Pick a service which you would like to migrate
- Most services should require minimal to no change.
- Configure the service in Angular 2
- (optionally) re-export the service into Angular 1 using ng-upgrade if it’s still used by other parts of your Angular 1 code.
- Repeat doing step #2 and #3 in an order convenient for your application development
- Once no more services/components need to be converted drop the top level Angular 1 bootstrap and replace with Angular 2 bootstrap.
- The new Angular 2 router is being backported to Angular 1, and will allow the same application to have both Angular 1 and Angular 2 routes
- It will be possible to mix Angular 1 and Angular 2 components in the same application
- It will be possible to inject services across framework versions
- Data binding will work across versions as the two change detection mechanisms will be integrated.
4. why Angular 2?
AtScript provides tools for associating metadata with functions. This facilitates the construction of object instances by providing the required information to the DI library (which will check for associated metadata when calling a function or creating an instance of a class). It will be also easy to override parameter data by supplying an Inject annotation.
B. Child Injectors
A child injector inherits all the services of its parent with the capability of overriding them at the child level. According to requirement, different types of objects can be called out and automatically overridden in various scopes.
C. Instance Scope
The improved DI library will feature instance scope control, which will become even more powerful when used with child injectors and your own scope identifiers.
D. Dynamic Loading
This is a feature which is missing from the current version of Angular. It will be addressed by Angular 2.0, which will let developers add new directives or controllers on the fly.
In Angular 2.0, the template compilation process will be asynchronous. As the code is based on the ES6 module spec, the module loader will load dependencies by simply referencing them in the component definition.
In Angular 2.0 there will be three kinds of directives: Component Directives, Decorator Directives, Template Directives
The router in Angular 2.0 has been reworked to be simple, yet extensible. It will include the following basic features:
- Simple JSON-based Route Config
- Optional Convention over Configuration
- Static, Parameterized and Splat Route Patterns
- URL Resolver
- Query String Support
- Use Push State or Hashchange
- Navigation Model (For Generating a Navigation UI)
- Document Title Updates
- 404 Route Handling
- Location Service
- History Manipulation
H. Child Router
The child router will convert each component of the application into a smaller application by providing it with its own router. It will help encapsulate entire feature sets of an application.
I. Screen Activator
This will give developers finer control over the navigation lifecycle, via a set of can* callbacks:
canActivate – Allow/Prevent navigating to the new controller.
activate – Respond to successful navigation to the new controller.
canDeactivate – Allow/Prevent navigation away from the old controller.
deactivate – Respond to successful navigation away from the old controller.
These callbacks will allow the developer to return Boolean values, a Promise for that value, or a Navigation Command (for a lower level control).
Angular 2.0 will contain a logging service called diary.js—a super useful feature which measures where time is spent in your application (thus enabling you to identify bottlenecks in your own code).
5. Angular Security