75

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?

Vy Do
  • 46,709
  • 59
  • 215
  • 313
Damith
  • 1,982
  • 3
  • 28
  • 42
  • 3
    Possible duplicate of ['angular2/platform/browser' vs. '@angular/platform-browser-dynamic'](http://stackoverflow.com/questions/37993476/angular2-platform-browser-vs-angular-platform-browser-dynamic) – Louis Mar 20 '17 at 13:31

5 Answers5

45

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.

hAmpzter
  • 317
  • 2
  • 5
Arpit Agarwal
  • 3,993
  • 24
  • 30
18

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.

uzay95
  • 16,052
  • 31
  • 116
  • 182
8

"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

Ram MK
  • 93
  • 1
  • 6
5

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

Balu
  • 456
  • 8
  • 19
4

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

hAmpzter
  • 317
  • 2
  • 5
pd farhad
  • 6,352
  • 2
  • 28
  • 47