4

I am new to Angular. I have learned Angular's basic notions and understand the project structure.

But when I use the Angular-CLI generate a basic project, I find in the project there is no NgModule in the root src folder. But accord to the docs in the homepage of Angular, the root was NgModule. So here is my question, what is the difference between them, and why does the Angular-CLI use the component as the root? Thanks.

2 Answers 2

1

I think angular-cli has not been updated yet. Angular 2 is still changing fast.

BUT, you can create it easily by yourself:

$ ng new yourproject

then navigate inside yourproject/src/ folder, replace main.ts this way:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

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

platformBrowserDynamic().bootstrapModule(AppModule);

now go into the yourproject/src/app folder and create app.module.ts:

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MdButtonModule } from '@angular2-material/button';

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

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

You may also need to add/update some dependecies in yourproject/package.json. Here are mine:

  "dependencies": {
    "@angular/common": "2.0.0-rc.5",
    "@angular/compiler": "2.0.0-rc.5",
    "@angular/core": "2.0.0-rc.5",
    "@angular/forms": "0.3.0",
    "@angular/http": "2.0.0-rc.5",
    "@angular/platform-browser": "2.0.0-rc.5",
    "@angular/platform-browser-dynamic": "2.0.0-rc.5",
    "@angular/router": "3.0.0-rc.1",
    "@angular/router-deprecated": "2.0.0-rc.2",
    "@angular/upgrade": "2.0.0-rc.5",
    "bootstrap": "^3.3.6",
    "core-js": "^2.4.0",
    "es6-shim": "0.35.1",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "0.19.27",
    "zone.js": "^0.6.12"
  },
  "devDependencies": {
    "angular-cli": "1.0.0-beta.10",
    "codelyzer": "0.0.20",
    "ember-cli-inject-live-reload": "1.4.0",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "0.13.22",
    "karma-chrome-launcher": "0.2.3",
    "karma-jasmine": "0.3.8",
    "protractor": "3.3.0",
    "ts-node": "0.5.5",
    "tslint": "^3.7.4",
    "typescript": "^1.8.10",
    "typings": "1.3.1"
  }
Sign up to request clarification or add additional context in comments.

Comments

0

its because to date as far as i know Angular2 cli run's on rc4 and not rc5 by the default npm install, the example you see is for rc5 libraries (NgModule) - and not rc4, you should choose the most convenient version for you, because the release candidate versions tends to update quickly anyway.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.