Невозможно связать с «menuList», поскольку оно не является известным свойством «tree-view» - PullRequest
0 голосов
/ 16 мая 2018

Я пытаюсь реализовать код, указанный в ссылке ниже

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

EDIT

Ниже приведен код, который я реализовал для 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 {
}

Есть ли какая-нибудь подсказка для этого?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...