Ced
Ced

Reputation: 17327

@NgModule is that new?

I'm learning angular 2 via a book that I just bought (become a ninja with angular 2).

I'm also going through the official doc in parallel but when doing the quickstart from the official site I see they are talking about @NgModule while there is no mention of it in the book.

So I would like to know if the official doc is up to date and if indeed NgModule is a new thing. I think I read somewhere that the doc wasn't up to date, so I wouldn't like to use something that is soon to be deprecated.

Here is how they are bootstrapping the app in the book :

import { bootstrap } from '@angular/platform-browser-dynamic';
import PonyRacerAppComponent  from './app/ponyracer-app.component';

bootstrap(PonyRacerAppComponent).catch(err => console.log(err)); 

And here is how they are bootstrapping the app in the official quick start :

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import
       { AppComponent }  from './app.component';

@NgModule({
  imports: [ BrowserModule ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

then in another file :

// The browser platform with a compiler
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

// The app module
import { AppModule } from './app.module';

// Compile and launch the module
platformBrowserDynamic().bootstrapModule(AppModule);

Upvotes: 4

Views: 4026

Answers (3)

Anmol Saraf
Anmol Saraf

Reputation: 15743

Yes this is a new and well integrated in Angular 2 final stable release now.

This is very nicely explained in the article by Jecelyn Yeen at - https://scotch.io/bar-talk/getting-to-know-angular-2s-module-ngmodule#module-in-angular-2

Module in Angular 2

Fast forward to Angular 2. Angular Module is now called @NgModule.

Question 1 Why do we need @NgModule?

Upvotes: 0

Jorawar Singh
Jorawar Singh

Reputation: 7621

@NgModule is that new? => Yes

Yes in angular2 rc5 but i think it's almost the same concept as angular 1.x

Modules are a great way to organize the application and extend it with capabilities from external libraries.

Many Angular libraries are modules (e.g, FormsModule, HttpModule, RouterModule). Many third party libraries are available as Angular modules (e.g., Material Design, Ionic, AngularFire2).

Angular modules consolidate components, directives and pipes into cohesive blocks of functionality, each focused on a feature area, application business domain, workflow, or common collection of utilities.

Modules can also add services to the application. Such services might be internally-developed such as the application logger. They can come from outside sources such as the Angular router and Http client.

Modules can be loaded eagerly when the application starts. They can also be lazy loaded asynchronously by the router.

Source

Upvotes: 2

Related Questions