What is Angular platform-browser?

Angular

Angular Problem Overview


I am new to Angular 2. I have seen in every project there is plugin called platform-browser.

"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",

I don't really know what is the usage of it. Someone can please explain me

  • What is the usage of platform-browser?
  • What is the problem if we not use platform-browser?

Angular Solutions


Solution 1 - Angular

Your Angular application can start off in many ways, but when you run on the browser you have a specific way of bootstrapping the application and that is defined in @angular/platform-browser-dynamic.

In short these packages contain angular features which make getting an Angular app up and running possible in the browser. Bootstrapping is essential and one of those features.

You can omit this when your target is not to develop the app to run on browser otherwise it is essential.

Solution 2 - Angular

In Angular 1 we were bootstraping app using by ng-app attribute once in the index.html file.

<div ng-app='my-app'> </div>

enter image description here

But in Angular 2 we need to pass which component will be the root using by

platformBrowserDynamic().bootstrapModule(AppModule)

As you've seen we don't pass directly the component as parameter to bootstrapModule method. But in the root module(in this sample code it is AppModule) we must pass the root component. Below you'll see app.module.ts file's class AppModule (root module of the app):

enter image description here

You may want to read this.

Solution 3 - Angular

"Platform-browser" Package is used to control some of the following browser things.

  1. We can change the title of the page dynamically.
  2. Its used to set,get,update browser meta data's
  3. Also we can disable or enable browser debugging tool with the help of functions available in this package

There are many other things also there.

Please see the below URL https://angular.io/api/platform-browser

Solution 4 - Angular

Angular 2 Bootstrapping is platform-specific

We use the bootstrap function from ng.platformBrowserDynamic, not from ng.core. There's a good reason.

We only call "core" those capabilities that are the same across all platform targets. True, most Angular applications run only in a browser and we'll call the bootstrap function from this library most of the time.

Reference: https://angular.io/guide/quickstart

Solution 5 - Angular

This tells, how the application should be compiled. AOT/JIT. AOT compiles it in advance(Pre-compiled) and JIT does it at the browser level. The application code downloaded to the browser is smaller than the one done for JIT(dynamic version). The JIT compiler creates these classes on the fly in browser. Anyhow, the application module (AppModule) is never care how this is been bootstapped.

Please see the documentation : https://angular.io/guide/ngmodule

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDamithView Question on Stackoverflow
Solution 1 - AngularArpit AgarwalView Answer on Stackoverflow
Solution 2 - Angularuzay95View Answer on Stackoverflow
Solution 3 - AngularRam MKView Answer on Stackoverflow
Solution 4 - Angularpd farhadView Answer on Stackoverflow
Solution 5 - AngularBaluView Answer on Stackoverflow