我有一个 Angular 2 应用程序,现在我想使用双向绑定(bind)。当我尝试分配 imports: [FormsModule]
时,发生错误:
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'.
这是代码:
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]
})
最佳答案
您不能在组件中使用导入
。您应该在 ngModule
装饰器中导入所有必需的依赖项。
请查看 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 { }
关于javascript - Angular 2 - 'imports' 不存在于类型 'ComponentMetadataType' 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39037271/