【发布时间】:2023-02-01 11:28:01
【问题描述】:
`我在 Angular html 文件中做了这个:
<div class="modal-body">
<app-add-edit-dep [dep]="dep" *ngIf="ActivateAddEditDepComp">
</app-add-edit-dep>
</div>
现在错误是: 错误:src/app/department/show-dep/show-dep.component.html:23:31 - 错误 NG8002: 无法绑定到“dep”,因为它不是“app-add-edit-dep”的已知属性。
- 如果“app-add-edit-dep”是一个 Angular 组件并且它有“dep”输入,那么验证它是这个模块的一部分。
your text - 如果“app-add-edit-dep”是 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到此组件的“@NgModule.schemas”以抑制此消息。
- 要允许任何属性,请将“NO_ERRORS_SCHEMA”添加到此组件的“@NgModule.schemas”。
这是 Angular TS 文件:
import { Component, OnInit } from '@angular/core'; import { SharedService } from 'src/app/shared.service'; @Component({ selector: 'app-show-dep', templateUrl: './show-dep.component.html', styleUrls: ['./show-dep.component.css'] }) export class ShowDepComponent implements OnInit { constructor(private service:SharedService) { } DepartmentList:any=[]; ActivateAddEditDepComp:boolean=false; dep:any; ModalTitle:string; ngOnInit(): void { this.refreshDepList(); } addClick(){ this.dep={ DepartmentId:0, DepartmentName:"" } this.ModalTitle="Add Department"; this.ActivateAddEditDepComp=true; } closeClick(){ this.ActivateAddEditDepComp=false; this.refreshDepList(); } refreshDepList(){ this.service.getDepList().subscribe(data=>{ this.DepartmentList=data; }); } }
【问题讨论】:
标签: angular typescript data-binding two-way-binding