I am new in Angular, I am using Angular 4, and I made an app using the Angular CLI, by ng new
command.
In main.ts, we have
...
import {AppModule} from './app/app.module';
.
.
platformBrowserDynamic().bootstrapModule(AppModule);
and AppModule is defined (as you see) in app/app.module
, here is what we have in app.module.ts
:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
As you see it says export class AppModule { }
, and it also used in platformBrowserDynamic().bootstrapModule(AppModule);
Can someone please explain this for me?
Angular imports/exports are used to make the content of one module available to be used in another module. Allows you to use the directives from FormsModule and AuthRoutingModule in AuthModule and registers the services provided by these modules in the AppModule scope or the closed lazy-loaded root scope.
index. ts help us to keep all related thing together and we don't need to worry about the source file name. We can import all thing by using source folder name. import { getName, getAnyThing } from './util'; Here util is folder name not file name which has index.
Tell Angular how to construct and bootstrap the app in the root "AppModule". An Angular module class describes how the application parts fit together. Every application has at least one Angular module, the root module that you bootstrap to launch the application.
You can export any declarable class —components, directives, and pipes— whether it's declared in this NgModule or in an imported NgModule. You can re-export entire imported NgModules, which effectively re-export all of their exported classes. An NgModule can even export a module that it doesn't import.
The body of the class is indeed empty. But that decorator above the class (@NgModule
) is giving that class its functionality. So really, that class isn't empty. It just doesn't require any extra logic after the decorator is applied to it. bootstrapModule
takes a class as input and assumes that that class is decorated with @NgModule
configured in a manner similar to what you have (declarations, imports, providers, etc.).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With