No NgModule in folders created using Angular -Cli

I am new to angular.js. I learned the basic concepts of angular.js and understood the structure of the project.

But when I use angular-cli, I generate the base project, I find in the project that there is no NgModule in the src root folder. But agreeing with the docs on the angular homepage, the root was NgModule. So, here is my question, what is the difference between the two. And why does angular-cli use the component as the root? Thank.

+4
source share
2 answers

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

BUT, you can easily create it yourself:

$ ng new yourproject

then go to the folder yourproject/src/, replace main.tsas follows:

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

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

platformBrowserDynamic().bootstrapModule(AppModule);

yourproject/src/app 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 { }

/ yourproject/package.json. :

  "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"
  }
+1

, , Angular2 cli rc4, rc5 npm install, , , rc5 (NgModule) - rc4, , - .

0

Source: https://habr.com/ru/post/1652790/


All Articles