Angular 7.0 – What is New in its new Avatar?

The strength of a building is in its concrete pillars. So is the framework for a web application. A software framework provides a standard way to design, build and deploy applications. In a world of Java platforms, the Javascript framework was the most uttered buzzword until Angular gained importance.

Now, let us see some Salient features of Angular.

  • Angular is an Open source Javascript framework which morphed into what is called ‘Typescript’ now.
  • Code generation and development are rapid compared to a (Javascript) JS code.
  • The Command line prompt (CLI) has commands to build application faster.
  • The Code is well organized as it uses components hence improves productivity
  • A directive is a dynamic function that handles variables, if statements, and loops in HTML
  • Angular is cross-platform hence it is independent of the browser and the operating system
  • Angular CLI comes with testing tools that are helpful for unit testing

AngularJS – A precursor to Angular

AngularJS was the first product in the Angular series introduced by Google in 2009. It is a client-side or a front-end framework. What this means is that the code runs on the user’s browser and not on the web server. AngularJS was written purely in Javascript. This was developed to decouple the application logic, however, it was the only fairly successful and paved way for Angular with its current avatar 7.0.

Is AngularJS Right Choice For Your Next Mobile App Development?

 

Angular 7.0 Framework

Let us understand briefly the building blocks of Angular:

  1. Module:  Basically breaks down application’s core screens logically. For example, if there is a shopping cart page, one might want to have a shopping cart module.
  2. Component: This is a section of the UI and is a ‘class’ as in object-oriented programming. This is the fundamental building block of the User Interface (UI). The component class contains the core logic for the page.
    Components are made up of:

    1. Template: A template is written in HTML or they can be HTML files. It can have dynamic properties like variables and use of ‘if conditions’ is possible with directives.
    2. Class: Is the code for the application. The code is written in Typescript. Typescript is a superset of Javascript. Typescript is a ‘static’ type language where variables are declared with types defined. Hence errors are caught on the compilation of the program rather than being caught at runtime. Angular classes can be written in Javascript too. Components have data properties and methods. 
    3. Metadata: To identify that the class is an Angular component one uses Metadata. Metadata can be attached to Typescript using a decorator declaration.
      Let us walk through a simple component in Angular.

      Import {component} from  ‘’@angular/core’’ ; Here the component package is imported from Angular core library.
      @component ({     (this is a decorator declaration)
                            Selector : ‘myapplication’   …(.this is the custom HTML tag that we use to insert the component. )
                            Template: ‘<h1> Hello {(name)}</h1> (name is a variable)
                 })
      export class AppComponent{       (This is the component class and ‘name’ is a property in the class)
                             name = ‘ Angular framework’;
                 }
                 <body>
                 <myapplication>Loading a sample app component here..</myapplication>
                 </body>
    4. Data binding: A process that allows communication between the component and the view. So data is passed from the component to the view and vice-versa. There are four types of data binding. In Interpolation and property binding the data is sent from the component to the view and in event binding, the data is sent to the component from the view or the template. In two-way binding, the data travels both ways.
    5. Service: This is a class that is written for reusable code, i.e. code that can be accessed from multiple components. These classes send data and functionality across components. Service classes can also get data from a database or a js/JSON file. When one uses a Service class, the code looks organized and fragmented.
    6. Directive: Customizing HTML attributes to extend the power of HTML is a directive.  ngIf, ngFor, ngModel are directives. ngModel is responsible for, binding the view into the model, which other directives such as input, textarea or Select require.
      Here is a piece of code that shows how ngmodel works.

      <div ng-app="" ng-init="firstName='John'">
      <p>Input a name in the input box:</p>
      <p>Name: <input type="text" ng-model="firstName"></p>
      <p>You wrote: {{ firstName }}</p>
      </div>
      

      So, firstName was initialized to ‘John’ and when one enters a new value in the text box, firstName will hold the new name entered.

    7. Dependency injection (DI): Classes need objects to perform a particular function. Instead of creating the objects each time in the class, the class receives the objects(dependencies) from external sources. In the DI framework following are the steps that need to be followed:
      1. Create a Service Class eg. Employeedata
      2. Register this service class with the Injector. An Injector is a container that holds all the dependency classes
      3. Declare the Employeedata class as a dependency in the class that needs it eg. EmployeeList Class
What Does A Software Developer Do?

 

Versions of Angular

After AngularJS, Angular 2 was released which was a complete rewrite of AngularJS. Components got added from Angular 2. Angular 2 was not backwards compatible. Angular is made up of a bunch of packages and the Router package in Angular 3 was not in sync. Hence the Angular team moved on to Angular 4 which was released with all corrections and features with backward compatibility to Angular 2. Subsequently Angular 5, Angular 6 was released and the latest version now is Angular 7.

What’s new in Angular 7.0?

  1. CLI Prompts: A change in the Angular command line prompt is that the CLI prompts the user, to select the features while running the common commands. Features like Angular routing or the format of the style-sheet and many more can be selected by the user. In the previous versions of Angular one had to remember and type the options on the prompt.
  2. Application Performance :
    1. Common errors:
      In this version, the angular team analyzed and removed some common mistakes made by the developers like the ‘reflect-metadata’ polyfill was included in production which is actually needed only in development.
    2. Bundle-Budgets:
      To improve the performance of the application, default Bundle Budgets are defined in angular.JSON. The developers will now be warned if the application bundle size exceeds a limit of 5MB and when the initial bundle exceeds 2MB. These values can be modified in the JSON file as needed.
  3. Angular Material & the CDK: The Angular component development kit(CDK) was created from the Angular Material(UI for libraries).The two new features added in the CDK are
    1. Virtual Scrolling:
      To load only the visible part on the screen, the <cdk-virtual-scroll-viewport> package provides helpers for directives that react to scroll events. So, it will render only the items that can fit on the screen. When a user scrolls through the list then the DOM will load and unload the elements dynamically based on the display size.
    2. Drag and Drop support:
      The @angular/cdk/drag-drop module helps free drag and drop feature of an element, reordering items in a list, moving items in a list and so on. This is done with the help of cdkDropList and cdkDrag directives.
  4. Angular 7.0 has updated its dependencies to support Typescript 3.1, RxJS 6.3 and Node 10.
  5. Improved accessibility of Selects: The native ’select’ has some performance, accessibility, and usability advantages hence using a native select element inside a ‘mat-form-field’ is a new feature in Angular 7.0.
  6. Angular elements: A small change but new in Angular 7
    Angular Elements now supports content projection using web standards for custom elements.” — This is what Stephen Fluin, Angular says.
  7. Working with partners: The Angular team has been working to partner with community projects that have been launched recently one of them is Angular Console. Angular Console is a user interface for Angular CLI. It is good for beginners and experts as it is a lot easier than prompts. There are different UI versions for Windows and Mac OS.
A Beginner’s Guide to MVC Architecture in Java

 

Most of the changes in Angular 7.0 are on performance improvements and bug fixing. Hence, it is the safest version to date and migrating from earlier versions is simple. Ivy is the new upcoming rendering engine that the Angular team is working on. Till then, let us wait and watch. Keep Learning!

Facebook Comments

Become a Full Stack Developer

UpGrad and IIIT-Bangalore's PG Diploma in Software Development
Learn More