Jack Chen
Jack Chen

Reputation: 670

Angular 2 - 'imports' does not exist in type 'ComponentMetadataType'

I have an Angular 2 application, and now I want to use two-way binding. When I try to assign imports: [FormsModule], there is an error happened:

Argument of type '{ imports: typeof F...' is not assignable to parameter of type 'ComponentMetadataType'.
Object literal may only specify known properties, and 'imports' does not exist in type 'ComponentMetadataType'.

Here is the code:

import {Component, OnInit} from '@angular/core';
import  {TodoService} from '../todo.service'
import {FormsModule} from '@angular/forms'

@Component({
  moduleId: module.id,
  selector: 'app-todos',
  templateUrl: 'todos.component.html',
  styleUrls: ['todos.component.css'],
  imports: [FormsModule]
})

Upvotes: 2

Views: 3645

Answers (1)

Alex M
Alex M

Reputation: 2836

You can't use imports in components. You should import all required dependencies in the ngModule decorator.

Please have a look at the following example form the Angular JS documentation:

import { NgModule }      from '@angular/core';
import { FormsModule }   from '@angular/forms';
import { AppComponent }  from './app.component';

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

export class AppModule { }

Upvotes: 3

Related Questions