Introduction
In this article, I will explain what the new changes that come with Angular 4.0 are. AngularJS is one of the most poupular JavaScript frameworks to create Web apps. It is maintained by Google.
In this article, I will explain what the new changes that come with Angular 4.0 are. AngularJS is one of the most poupular JavaScript frameworks to create Web apps. It is maintained by Google.
What's new in AngularJs 4.0?
One of the most important things is that Angular 4.0 doesn't change that much. In Angular 4.0, some under the hood changes, some improvements, and performance improvements have been done. According to Angular change-log the "Angular 4.0 release is backwards compatible and will work with your existing code, but you may have use cases they haven’t anticipated"
One of the most important things is that Angular 4.0 doesn't change that much. In Angular 4.0, some under the hood changes, some improvements, and performance improvements have been done. According to Angular change-log the "Angular 4.0 release is backwards compatible and will work with your existing code, but you may have use cases they haven’t anticipated"
Let's see what are the new changes made in Angular 4.0.
ngIf,
In Angular 2.0, if we wanted to use ngIf with multiple conditions or specifically with else, we write, as shown below.
In Angular 2.0
ngIf,
In Angular 2.0, if we wanted to use ngIf with multiple conditions or specifically with else, we write, as shown below.
In Angular 2.0
- <button (click)="showPara=!showPara">Show and Hide Paragraph</button>
- <p *ngIf="showPara">This time show paragraph value is true</p>
- <p *ngIf="!showPara">This time show paragraph value is false</p>

In Angular 4.0
NgIf syntax has been extended to support the else clause to display the template when the condition is false. In addition, the condition value can now be stored in local variable for later reuse. This is especially useful when used with the async pipe.
Example
- <button (click)="showPara=!showPara">Show and Hide Paragraph</button>
- <p *ngIf="showPara;else hidePara">This time show paragraph value is true</p>
- <ng-template #hidePara>
- <p>This time show paragraph value is false</p>
- </ng-template>
You can also store the value in a local variable and later you can use it.
- <div *ngIf="employeeObservable | async; else loading; let emp">
- Hello {{emp.first}} {{emp.last}}!
- </div>
- <template #loading>Waiting...</template>
There is one more part, which is added that is "then". We can check the condition and using then, we can show different templates. The syntax is given below.
- <div *ngIf="condition; then thenBlock else elseBlock"> ... </div>
- <template #thenBlock>Then template</template>
- <template #elseBlock>Else template</template>
Email Validator
In Angular 2.0, we use an email validator, using pattern option. We provided an email pattern in pattern attribute and then we check whether the form is valid or not but in Angular 4.0, there is a validator to validate an email.
In Angular 2.0
In Angular 2.0, we use an email validator, using pattern option. We provided an email pattern in pattern attribute and then we check whether the form is valid or not but in Angular 4.0, there is a validator to validate an email.
In Angular 2.0
- <form #frm="ngForm">
- <label>Email</label>
- <input
- type="email"
- ngModel
- name="email"
- required
- style="width:300px"
- pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$"/>
- <button [disabled]=!frm.valid>Submit</button>
- </form>
In Angular 4.0
We can use an email Directive, which is shown below.


Manav PandyaPosted Apr 11, 2018, 5:19 AM
Update AngularJs 4.0 to Angular 4
Kapi ShivharePosted Aug 26, 2017, 3:48 AM
Nice article info... Sourabh Somani
Anil JhaPosted Jul 14, 2017, 2:06 AM
Thanks for sharing...
Hamid KhanPosted Apr 17, 2017, 11:50 AM
Thanks for sharing Sourabh
Joginder BangerPosted Mar 27, 2017, 9:19 AM
Thanks for sharing sir..
Upendra Pratap ShahiPosted Mar 27, 2017, 8:10 AM
Nice one info Sourabh Somani....
Amit MishraPosted Mar 27, 2017, 6:09 AM
Nice Sourabh Sir, nice explanation with example
Thiruppathi RPosted Mar 27, 2017, 5:15 AM
I am not expecting like this level of approach ,but very powerful Angular 4. Thank you @Sourabh Somani.