Wednesday, 13 July 2016

Angular 2 - Initial Impression

After working mainly with ASP.Net MVC for Web UI and some other JavaScript libraries, i finally got around to taking a look at Angular 2.

In this post i'll post my initial impressions and will dig deeper into Angular 2 in future posts.

First thing that got my attention is the Typescript Language, which is the language of choice for Angular 2. Typescript is a language developed by Microsoft and is a sort of an abstraction over JavaScript. Any code that is written in TypeScript eventually gets compiled/transpiled into JavaScript.  TypeScript felt closer to and Object Oriented Language like C# or Java, rather than the messy JavaScript. It has concepts like Classes, Constructors, Interfaces, Properties, Methods, Events, Strongly typed data types. As my main programming language has been C#, I found Typescript to be a pretty cool language which makes writing client side code a breeze. However, ppl who may have a a JavaScript background might have a different opinion about TypeScript..


Another thing that stood out was the discarding of the MVC / MVVM architecture which has been the trend in UI in the last few years (ASP.Net MVC, AngularJS, etc.) and using a component based architecture. Basically, the UI is broken down into smaller pieces and these pieces need to be implemented as a Component. A Component is  a TypeScript Class (with a Component Directive) and it would have it's UI html fragment in a separate Template file. The properties, methods, events and any logic would be in the TypeScript Class and the Template would bind to data in these as well as call it's methods and events. For those of you who have experience working with ASP.Net Web Forms, it might feel eerily similar to User Controls, with the UI Template file feeling like the UI *.ascx and the Component *.ts file feeling like the Code-Behind *.ascx.cs.

These Components could then be nested under other Components or put in directly under the Root Component, which would be loaded/bootstrapped into an .html page.

An application could have additional Service class, which could perform tasks like getting data from a Web Service. Components could have instantiate a Service Class and use it's methods to get Data or alternatively, the Services could be declared at the Root Component layer and then injected into the Component via the Constructor.


My initial impression of Angular 2 has, surprisingly, been very positive and am looking forward to doing a bit of deep diving into it. 

No comments:

Post a Comment