Reputation: 2082
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
?
Upvotes: 80
Views: 72862
Reputation: 16632
In Angular 1 we were bootstraping app using by ng-app attribute once in the index.html file.
<div ng-app='my-app'> </div>
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):
You may want to read this.
Upvotes: 20
Reputation: 93
"Platform-browser" Package is used to control some of the following browser things.
There are many other things also there.
Please see the below URL https://angular.io/api/platform-browser
Upvotes: 8
Reputation: 4003
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.
Upvotes: 46
Reputation: 6432
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
Upvotes: 4
Reputation: 476
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
Upvotes: 5