Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of polyfills.ts file in Angular

polyfills.ts file is auto generated while creating an Angular application using Angular Cli. Can anyone explain me what is the use of polyfills.ts file in Angular application.

like image 306
Praveen Ojha Avatar asked Oct 09 '22 14:10

Praveen Ojha


People also ask

What is the use of polyfills?

A polyfill is a piece of code (usually JavaScript on the Web) used to provide modern functionality on older browsers that do not natively support it.

What is main TS file in Angular?

main. ts file is the entry point of our web-app.It compiles the web-app and bootstraps the AppModule to run in the browser. It starts with importing the basic module which we need. platformBrowserDynamic().bootstrapModule(AppModule) This code has reference to the parent module i.e AppModule.

How do you add polyfills in Angular 12?

Optional polyfills: You need to install its npm package and then create import statement in 'src/polyfills. ts' file. For example, first you need to install below npm package for adding web animations (optional) polyfill. bash npm install --save web-animations-js and create import statement in polyfill file.

What is the use of * in Angular?

It's called Safe Navigation Operator which can be used to prevent Angular from throwing errors, when trying to access object properties of an object that don't exist. Here it is, protecting against a view render failure if the header is null.


1 Answers

Polyfills in angular are few lines of code which make your application compatible for different browsers. The code we write is mostly in ES6(New Features: Overview and Comparison) and is not compatible with IE or firefox and needs some environment setups before being able to be viewed or used in these browsers.

Polyfills.ts was provided by angular to help you do away with need to specifically setup everything.

From Docs

Angular is built on the latest standards of the web platform. Targeting such a wide range of browsers is challenging because they do not support all features of modern browsers.

Read more here

like image 124
Sajeetharan Avatar answered Oct 12 '22 10:10

Sajeetharan