Professional Documents
Culture Documents
Discuss Angular 4
Changes have been made under the hood to what AOT generated code looks like.
These changes reduce the size of generated code.
The purpose of Angular 4 is to reduce the size of the generated code for a component
by an average of 60-65%.
According to Google metrics, generated code had been about 10 times the size of the
original template. With this release, generated code is now only 3 times the size of the
original template.
Introduction to Angular 4
FORM FEATURE: EMAIL VALIDATION IN REACTIVE FORM
• Now you have email validator in forms to validate emails instead of using patterns.
• You need to just give email as an attribute to the input field where you want to have email id. Here
email is an angular directive; do not confuse with the type=”email” which is just an HTML DOM
type property.
Angular 4 Features
Topic 2—if…else Template Condition
if…else Template Condition
• The “ngIf” evaluates expression and then renders the “else” or “then” template in its place when
expression is “truthy” or “falsy” respectively.
Animations have been pulled out of @angular/core and put into their own package. This means that if you
don’t use animations, this extra code will not end up in your production bundles.
import {
animate,
state,
trigger } from '@angular/animations'
Angular 4 Features
Topic 4—TypeScript 2.1 and 2.2
TypeScript 2.1 and 2.2
This will improve the speed of ngc, and you will get better type checking
throughout your application.
In TypeScript 2.1 and 2.2 version, new quick fixes are available for unused
variables, unimplemented abstract methods, etc.
Angular 4 Features
Topic 5—Angular Universal
Angular Universal
Angular now ships flattened versions of modules. Angular 4 also ships the packages in
the ES2015 Flat ESM format.
FESM feature will help application in tree-shaking, and help to reduce the size of
generated bundles, speed up build, transpilation, and loading in the browser.
Developers have reported 6-7% bundle size savings when combining these packages
with Rollup.
Angular 4 Features
Topic 7—Router ParamMap
Router ParamMap
class MyComponent {
sessionId: Observable<string>;
ngOnInit() {
this.sessionId = this.route
.queryParamMap
.map(paramMap => paramMap.get('session_id') ||
'None');
}
}
Angular 4 Features
Topic 8—TypeScript StrictNullChecks
TypeScript StrictNullChecks
Null and undefined are JavaScript valid first class type citizens. Earlier, TypeScript didn't adhere to first class type
citizens, which meant you can't define a variable and tell TypeScript that this variable's value can be null or
undefined.
TypeScript StrictNullChecks feature is now compliant in Angular (v4), and the code is given below:
export class AppComponent implements OnInit{
ngOnInit() {
this.canBeNull = null;
console.log(this.canBeNull); // null
this.canBeUndefined = undefined;
console.log(this.canBeUndefined); // undefined
this.canBeNullOrUndefined = null;
console.log(this.canBeNullOrUndefined); //null
this.canBeNullOrUndefined = undefined;
console.log(this.canBeNullOrUndefined); // undefined
}
}
Key Takeaways
Animations have been pulled out of @angular/core, and now they have to be
used while adding the extra code in production bundles.
In TypeScript 2.1 and 2.2 version, new quick fixes are available for unused
variables, unimplemented abstract methods, etc.
Universal is the project that lets the programmers run Angular on a server, and it
is now up to date with Angular.
Angular now ships flattened versions of modules, and ships the packages in the
ES2015 Flat ESM format.
Quiz
QUIZ Which of the following has been pulled out of @angular/core and put into its own
1 package?
a. If…else Statement
b. Animation
c. Universal
d. FESM
QUIZ Which of the following has been pulled out of @angular/core and put into its own
1 package?
a. If…else Statement
b. Animation
c. Universal
d. FESM
a. FESM
b. Universal
c. Router ParamMap
d. StrictNullCheck
QUIZ ______________ is the project that lets the programmers run Angular on a server, and it is
2 now up to date with Angular.
a. FESM
b. Universal
c. Router ParamMap
d. StrictNullCheck