c# - 无法绑定到“menuList”,因为它不是“树视图”的已知属性
问题描述
我正在尝试实现下面链接中提到的代码
https://www.c-sharpcorner.com/article/recursive-tree-view-using-angular-2-and-typescript-till-nth-level-depth/
我对以下日志感到震惊。
An unhandled exception occurred while processing the request.
NodeInvocationException: Template parse errors:
Can't bind to 'menuList' since it isn't a known property of 'tree-view'.
1. If 'tree-view' is an Angular component and it has 'menuList' input, then verify that it is part of this module.
2. If 'tree-view' 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. ("<tree-view [ERROR ->][menuList]="menuList"></tree-view>"): ng:///AppModuleShared/TreeViewComponent.html@0:11
'tree-view' is not a known element:
1. If 'tree-view' is an Angular component, then verify that it is part of this module.
2. If 'tree-view' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<tree-view [menuList]="menuList"></tree-view>"): ng:///AppModuleShared/TreeViewComponent.html@0:0
Error: Template parse errors:
Can't bind to 'menuList' since it isn't a known property of 'tree-view'.
1. If 'tree-view' is an Angular component and it has 'menuList' input, then verify that it is part of this module.
2. If 'tree-view' 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. ("<tree-view [ERROR ->][menuList]="menuList"></tree-view>"): ng:///AppModuleShared/TreeViewComponent.html@0:11
'tree-view' is not a known element:
1. If 'tree-view' is an Angular component, then verify that it is part of this module.
2. If 'tree-view' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<tree-view [menuList]="menuList"></tree-view>"): ng:///AppModuleShared/TreeViewComponent.html@0:0
编辑
下面是我为 TreeViewComponent 实现的代码
import { Component } from '@angular/core';
import { TreeView } from './tree-view.directive';
import { ProjectRoleService } from './project-role.service';
@Component({
selector: 'tree-view-menu',
template: '<tree-view [menuList]="menuList"></tree-view>',
styleUrls: ['./tree-view.css']
})
export class TreeViewComponent {
public roleName: string = 'Admin';
menuList: any;
constructor(private _projectService: ProjectRoleService) {
}
ngOnInit() {
this.roleName = "Admin";
this._projectService.getMenuDetails(this.roleName).then((res: any) => {
this.menuList = res;
}, (error) => {
throw new Error('This request has failed ' + Response.error);
});
}
}
下面是 app.shared.module.ts 的代码。请在下面找到它。我删除了一些非常常见的导入。
import { AppComponent } from './components/app/app.component';
import { NavMenuComponent } from './components/navmenu/navmenu.component';
import { HomeComponent } from './components/home/home.component';
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
import { CounterComponent } from './components/counter/counter.component';
import { TreeViewMenuComponent } from './components/treeview/tree-view-menu.component';
import { TreeView } from './components/treeview/tree-view.directive';
@NgModule({
declarations: [
AppComponent,
NavMenuComponent,
CounterComponent,
TreeViewMenuComponent,
HomeComponent
],
imports: [
CommonModule,
HttpModule,
FormsModule,
RouterModule.forRoot([
{ path: '', redirectTo: 'tree-view-menu', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'counter', component: CounterComponent },
{ path: 'tree-view-menu', component: TreeViewMenuComponent },
{ path: '**', redirectTo: 'tree-view-menu' }
])
]
})
export class AppModuleShared {
}
这有什么线索吗?
解决方案
推荐阅读
- java - 如何在不使用关机的情况下停止 ThreadPool 中的线程
- c - c程序没有输出?
- http - #:~:text= 如何突出显示文本?
- woocommerce - 剪切文本并在 woocommerce 类别中添加阅读更多按钮
- swift - IOS GAME KIT 观察 GKInvite
- android - 如何在 Android 8 及更高版本中获取所有当前正在运行的进程 ID
- arduino - 通过 XBee 和 Arduino 发送 GPS 值(浮动问题!!!)
- java - 带有 testOnBorrow 的 Spring 中的 Apache Commons Pool 2(但不是在代理上的每个方法调用上)
- python - 如何使用 Python 绘制 Fry Graph 和 Raygor Graph 可读性?
- django - 在 Django 日志中使用唯一的用户标识符