最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular 2, Typescript Module has no exported constant 'FORM_DIRECTIVES' - Stack Overflow

programmeradmin9浏览0评论

I am trying to include one existing ponent in my app and from sample code I have these dependencies:

import {CORE_DIRECTIVES, FORM_DIRECTIVES, NgClass} from 'angular2/mon';

Now I am using '@angular' instead of 'angular2' which would I think be something like this:

import { Component, OnInit, CORE_DIRECTIVES } from '@angular/core';
import { FORM_DIRECTIVES } from '@angular/forms';

However I get this error

mypath/node_modules/@angular/forms/index"' has no exported member 'FORM_DIRECTIVES'.
mypath/node_modules/@angular/core/index"' has no exported member 'CORE_DIRECTIVES'.

How am I supposed to include FORM_DIRECTIVES and if they are no longer part of angular2 what is the replacement or new way to resolve dependencies?

I have checked angular changelog but couldn't find anything

I am trying to include one existing ponent in my app and from sample code I have these dependencies:

import {CORE_DIRECTIVES, FORM_DIRECTIVES, NgClass} from 'angular2/mon';

Now I am using '@angular' instead of 'angular2' which would I think be something like this:

import { Component, OnInit, CORE_DIRECTIVES } from '@angular/core';
import { FORM_DIRECTIVES } from '@angular/forms';

However I get this error

mypath/node_modules/@angular/forms/index"' has no exported member 'FORM_DIRECTIVES'.
mypath/node_modules/@angular/core/index"' has no exported member 'CORE_DIRECTIVES'.

How am I supposed to include FORM_DIRECTIVES and if they are no longer part of angular2 what is the replacement or new way to resolve dependencies?

I have checked angular changelog but couldn't find anything

Share Improve this question asked Sep 28, 2016 at 10:55 Darko RodicDarko Rodic 1,0203 gold badges10 silver badges27 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

FORM_DIRECTIVES are now part of FormsModule, so you should import FormsModule and add it to your module's imports.

CORE_DIRECTIVES are now part of CommonModule which is exported by BrowserModule. You already import BrowserModule in your AppModule, so you don't need to do anything about CORE_DIRECTIVES. Here's the example of basic module with imported FormsModule:

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

@NgModule({
    imports: [
        BrowserModule,
        FormsModule
    ],
    declarations: [
        AppComponent
    ],
    bootstrap: [AppComponent]
})

export class AppModule { }

you should to install :

npm install --save angular2

like that :

 "dependencies": {
    "@ngrx/store": "^1.2.1",
    "angular2": "^2.0.0-beta.7",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.2",
    "zone.js": "0.5.15"
  }

This works:

import {ControlGroup, Control, FORM_DIRECTIVES} from "angular2/mon";

@Component({
    selector: 'person-form',
    directives: [FORM_DIRECTIVES],
    template: require('./person_form.html')
})

export class PersonForm { ... } 
This fails with FORM_DIRECTIVES as undefined:

import {ControlGroup, Control} from "angular2/mon";

@Component({
    selector: 'person-form',
    directives: [FORM_DIRECTIVES],
    template: require('./person_form.html')
})

export class PersonForm { ... } 
发布评论

评论列表(0)

  1. 暂无评论