angularjs – Angular-Cli生成的文件夹中没有NgModule

我是angular.js的新手.我已经学习了angular.js的基本概念并理解了项目结构.

但是当我使用angular-cli生成一个基本项目时,我发现在项目中根src文件夹中没有NgModule.但是根据角度主页中的文档,根是NgModule.所以这是我的问题,它们之间有什么区别.为什么angular-cli使用组件作为根?谢谢.

最佳答案 我认为angular-cli还没有更新. Angular 2仍在快速变化.

但是,您可以自己轻松创建它:

$ng new yourproject

然后在你的项目/ src /文件夹中导航,用这种方式替换main.ts:

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 { }

您可能还需要在project / 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"
  }
点赞