最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin6PV0评论

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 { ... } 
Post a comment

comment list (0)

  1. No comments so far