What is Angular platform-browser?
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
?
Solution 1:
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.
- Platform-browser-dynamic
- Platform-browser
Solution 2:
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.