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
- 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 only fairly successful and paved way for Angular with its current avatar 7.0.
Angular 7.0 Framework
Let us understand briefly the building blocks of Angular.
- 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.
- 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:
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.
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 a compilation of the program rather than being caught at runtime. Angular classes can be written in Javascript too. Components have data properties and methods.
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: ‘
Hello {(name)}
(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
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.
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.
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.
Input a name in the input box:
Name: input type="text" ng-model="firstName">
You wrote: {{ firstName }}
So, firstName was initialized to ‘John’ and when one enters a new value in the text box, firstName will hold the new name entered.
- 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
Create a Service Class eg. Employeedata
Register this service class with the Injector. An Injector is a container that holds all the dependency classes
Declare the Employeedata class as a dependency in the class that needs it eg. EmployeeList Class
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 backward 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?
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.
Application Performance :
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.
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.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
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.
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.
Angular 7.0 has updated its dependencies to support Typescript 3.1, RxJS 6.3 and Node 10.
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.
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.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.
What’s next?
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.
Start Learn Angular