在使用@input属性声明组件的Angular模块中要导入什么?

时间:2019-12-26 10:09:17

标签: angular

角度8.X

之前,我将所有组件导入并在app.module.ts中声明 现在我正在为每个功能制作模块 但是对于声明@input的组件,我得到了错误:

**Uncaught Error: Template parse errors:
Can't bind to 'device' since it isn't a known property of 'igwan-device-detail'.
1. If 'igwan-device-detail' is an Angular component and it has 'device' input, then verify that it is part of this module.
2. If 'igwan-device-detail' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.** 

我的组件:

import { Component, OnInit, Input } from '@angular/core';


@Component({
  selector: 'igwan-device-detail',
  templateUrl: './device-detail.component.html',
  styleUrls: ['./device-detail.component.scss']
})

export class DeviceDetailComponent implements OnInit {
  @Input() device: any;
  @Input() alert: any;
  constructor() { }

  ngOnInit() {}

}

我的模块:

import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';

import { MatTableModule } from '@angular/material';
import { MatPaginatorModule } from '@angular/material/paginator';


import { ParkManagementComponent } from './park-management/park-management.component';
import { DeviceDetailComponent } from './device-detail/device-detail.component';


@NgModule({
  declarations: [DeviceDetailComponent],
  imports: [FormsModule, ReactiveFormsModule, CommonModule, MatTableModule, MatPaginatorModule],
  exports: [DeviceDetailComponent]
})
export class DeviceSearchModule { }

您知道还需要导入什么吗?

1 个答案:

答案 0 :(得分:0)

  

无法绑定到“设备”,因为它不是“ igwan-device-detail”的已知属性。

您组件的选择器是app-device-detail

@Component({
  selector: 'app-device-detail',
  templateUrl: './device-detail.component.html',
  styleUrls: ['./device-detail.component.scss']
})

所以选择'igwan-device-detail'的选择器:

@Component({
  selector: 'igwan-device-detail',
  templateUrl: './device-detail.component.html',
  styleUrls: ['./device-detail.component.scss']
})