Error: The Typescript module in Angular 2 does not have the constant 'FORM_DIRECTIVES' available for export

I need to integrate an existing component into my app, but I am facing some issues with the dependencies. Originally, the sample code provided me with these dependencies:

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

Now, I am transitioning to using '@angular' instead of 'angular2', which I believe should look something like this:

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

However, I encountered the following 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 can I include FORM_DIRECTIVES now that they are not part of angular2? What is the new way or replacement for resolving such dependencies?

I have searched through the angular changelog but couldn't find any relevant information.

Answer №1

FORM_DIRECTIVES have been incorporated into FormsModule, therefore, it is necessary to import FormsModule and include it in your module's imports.

CORE_DIRECTIVES are now included in CommonModule, which is exported by BrowserModule. Since you are already importing BrowserModule in your AppModule, there is no further action required for CORE_DIRECTIVES. Here is a sample of a 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.component';

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

export class AppModule { }

Answer №2

To properly set up your project, you need to follow these steps:

npm install --save angular2

Additionally, make sure you have the following dependencies in your package.json file:

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

After setting up the project, you can use the following code successfully:

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

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

export class PersonForm { ... } 
Unfortunately, if you exclude FORM_DIRECTIVES, it will result in an error:

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

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

export class PersonForm { ... } 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountered an issue during installation: Error message states that Typings command was not

I've encountered permission errors with npm, so I decided to reinstall it. However, I'm facing an issue with the 'typings' part where it displays a 'typings: command not found' error. This problem seems to be related to Angula ...

Is there a way to format this into four columns within a single row while ensuring it is responsive?

I am working on a layout with a Grid and Card, aiming to have 4 columns in one row. However, the 4th column ends up in the 2nd row instead, as shown below: https://i.sstatic.net/gOeMm.png My goal is to align all 4 columns in a single row. Additionally, w ...

Tips on incorporating a URL from a text file into a string

Could anyone assist me in adding a URL text file containing just one sentence and saving it as a string? Your help would be greatly appreciated. Thank you. ...

Utilize Vue Component by assigning a computed property to the data source

Trying to assign a computed property value to a component's data in order to fetch and manipulate localStorage data. After mounting the component, I want to monitor changes in the localStorage. If my key is updated, I need to retrieve the new value, ...

Can you explain what happens to "npm install" and "npm update" when modifications are made to package.json?

I'm struggling to understand why running the command "npm update" isn't updating my angular-cli to version 7.3.0, but when I use "npm install," it does update it to 7.3.0. Check out the macOS terminal screenshot below showing the upgrade from an ...

Implementing requirejs alongside retinajs for enhanced performance and compatibility

Currently, I am utilizing a combination of requirejs and retinajs as a plugin. To ensure smooth functioning, I am incorporating the shim feature along with a jQuery dependency: .... 'plugins/retina.min': { 'deps': ['jquery ...

Pinia has not been instantiated yet due to an incorrect sequence of JavaScript file execution within Vue.js

I'm currently developing a Vue.js application using Vite, and I have a Pinia store that I want to monitor. Below is the content of my store.js file: import { defineStore } from 'pinia'; const useStore = defineStore('store', { st ...

I'm having trouble importing sqlite3 and knex-js into my Electron React application

Whenever I try to import sqlite3 to test my database connection, I encounter an error. Upon inspecting the development tools, I came across the following error message: Uncaught ReferenceError: require is not defined at Object.path (external "path ...

Obtain the result and retrieve it using `window.angularComponentRef.zone.run`

In my work, I have been able to successfully call angular functions within a component through a static file. For reference, you can visit this link: How to expose angular 2 methods publicly?. The method suggested in the link involves using Zones in Angul ...

Encountering complications when importing TypeScript declarations

I am facing a problem with importing declarations from an extended file (I am utilizing this typing). As per the example, I have included this code in my project: import * as SockJS from 'sockjs-client'; import BaseEvent = __SockJSClient.BaseEve ...

I'm encountering an issue with VUEJS components including my show route in their get call. How can I make my journals/:id pages function properly without encountering a Mime

I encountered a MIME type error stating: Refused to apply style from 'http://localhost:8080/journals/assets/css/main.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. ...

React.js: You cannot call this expression. The type 'never' does not have any call signatures

Could someone help me troubleshoot the error I'm encountering with useStyles? It seems to be related to Typescript. Here's the line causing the issue: const classes = useStyles(); import React from "react"; import { makeStyles } from & ...

Provide props to vue-router along with boostrap-vue's b-nav-item

I am currently in the process of transitioning my SPA from modals that load components to routed pages that load components. I have been able to successfully open a page using to="/fixtures" in the html, but I am facing an issue with passing in a component ...

"Stay entertained with a captivating animated gif that appears when you refresh the

I just implemented this code snippet to enable animated gifs to work after refreshing a webpage. It's functioning properly in Chrome, Safari, and Internet Explorer except for Firefox. Can someone please offer assistance? jQuery: $(img).css("backgrou ...

Tips for resolving the error of encountering a forbidden and unexpected token in JSON at position 0 while using React hooks

const [forecastData, setForecastData] = useState({ forecast: []}); useEffect(() => { let ignore = false; const FETCHDATA = async () => { await fetch(forecast,{ headers : { ...

Troubleshooting localhost issue with a Chrome extension in Visual Studio Code

When working in VS Code, I encountered an issue with launching my HTML AngularJS project on localhost. Every time I try to launch the project, I receive an error message stating "Failed to load resource: net::ERR_CONNECTION_REFUSED (http://localhost:8080/) ...

express has a req.body that is devoid of any content

When making a request to my local server in my React app, the code looks like this: fetch("http://localhost:4000/signup", { method: "POST", mode: "no-cors", body: JSON.stringify({ name: "Joe", lname: "Doe& ...

If viewed on a mobile device, separate the array (indexed list) into two rows

Currently, I am working on my Ionic project where I am trying to implement an indexed list horizontally instead of vertically. While the list looks good as it is now, I want to make sure it supports smaller screen devices too by splitting the list into two ...

I am able to retrieve JSON data from the server using Angular, however, I am facing an

I have successfully accessed JSON data from the server, but I am struggling to display it properly. Currently, I can only show all models, but I want to display specific data. My template <!DOCTYPE html> <html> <head lang="en"> ...

Implementing circular generic in Typescript tutorial

I have a question regarding the code snippet below: interface BaseProps<TControl> { onEvent: (control: TControl) => void; } class BaseControl<TValue, BaseProps<any>> { onBlur = () => { onEvent(this); //subscriber must see ...