enfix
enfix

Reputation: 6970

How to include module in Angular 2

I'm new in Angular 2 and I'm following "The hero" tutorial.
I need to import these modules:

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

I start using Angular2 CLI (easy way to create app) but now when I'm trying to import these I got error like:

Error: Typescript found the following errors:"...node_modules/@angular/core/index"' has no exported member 'NgModule'.

How can I include its ?

Upvotes: 1

Views: 1021

Answers (2)

Brocco
Brocco

Reputation: 64893

Assumption you installed the angular-cli via npm install -g angular-cli

That version of the CLI is still based upon rc4, if you'd like to use the updated (current) version you will need to install it via:

npm uninstall -g angular-cli
npm cache clean
npm install -g angular-cli@webpack

And once you've done that, you can re-create your project and use the code you have above as you walk through the tour of heroes demo.

Upvotes: 1

m.chiang
m.chiang

Reputation: 185

Your syntax looks correct. You need to include these in the imports metadata array. NgModule uses the @NgModule Decorator which includes the imports array. You import them like this:

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

@NgModule({
    imports: [
        BrowserModule,
        FormsModule,
    ],

Also, when you are checking your package.json, ensure these are included in your 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",

after updating your package.json, run 'npm install' to update.

Upvotes: 0

Related Questions