简体   繁体   中英

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]
})

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM