Jack Chen Jack Chen - 2 months ago 40x
TypeScript Question

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'

moduleId: module.id,
selector: 'app-todos',
templateUrl: 'todos.component.html',
styleUrls: ['todos.component.css'],
imports: [FormsModule]


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';

  imports: [
  declarations: [
  bootstrap: [ AppComponent ]

export class AppModule { }