Laurent B
Laurent B

Reputation: 215

Angular 2 RC6 - Module vs. Component

I am really lost with RC6 of angular2.

I don't manage to adapt my code with module and component and don't understand the differences between the two. Could you help me in integrating directives, providers, imports for a large scale applications.

The Google's documentation is not so clear yet.

Thanks in advance.

Cheers

Upvotes: 3

Views: 1286

Answers (2)

Jeb50
Jeb50

Reputation: 7037

Forget about all those boring tech spec, they just confused you more. I don't really believe there is such need to have two concepts, because in programming language they can be referred interchangeably, like we say vehicles and cars. Many articles on Angular2 don't refer to them distinguishably for general discussion until actual coding.

However here are the two key differences when looking at code:

  1. Component has class, template and metadata.
  2. Component is child of Module, meaning Module is always at a higher level of Component.

About No. 2, that said means Component is the leaf-level in the Angular2 structure. Here is a very good explanation.

Upvotes: 1

Alex Beugnet
Alex Beugnet

Reputation: 4071

Basically, in Angular2, you have :

  • Modules : These are used to basically setup the logic of your application : How things are linked to each other. You start your application on bootstrapping a module.

    1. Imports : An array where you import the Angular2 Modules (Forms, etc.) and your next modules (DashboardModule, AdminModule, AuthentificationModule, etc.) as well as the Routing logic involved between your components.
    2. Declarations : An array where you declare the components that are linked to that module.
    3. Provider : An array where you declare your services or directives that are to be used with this module
  • Components : A "WebComponent" where you set the html to be injected into your navigator, with the associated CSS and it's behavior.

  • Services or Directives : Where you need to execute some app logic such as Authentication calls, states and so on.

  • A Router with outlets : That defines how you navigate in your application, based on the URL.

I tried to explain this with my own words so it's IS inaccurate on several levels, and that is why you have documentation sites such as angular.io. Hope this helps.

Official documentation on Modules => https://angular.io/docs/ts/latest/guide/ngmodule.html

Upvotes: 2

Related Questions