无法绑定到“项目”,因为它不是“树状视图”的已知属性

时间:2019-08-26 10:34:10

标签: angular typescript ionic-framework ionic4

以离子形式实现嵌套树视图,但是即使正确引用了库并在导入中添加了库,也显示了此错误。

App.Module

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
 // Import library
import { IonTreeViewModule } from 'ionic-tree-view';


 @NgModule({
 declarations: [AppComponent],
 entryComponents: [],
 imports: [BrowserModule, IonicModule.forRoot(), 
 AppRoutingModule,IonTreeViewModule],
 providers: [
 StatusBar,
 SplashScreen,
 { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
   ],
     bootstrap: [AppComponent]
 })
 export class AppModule {

}

主页

   export class HomePageModule {

   public items = [ ]  ;
   public persistedName = "";
   public treeViewName = "";
   constructor(){
this.items = [ { "id":1, "name":"features" }, { "id":2, "name":"Add", "parentID":1 }, { "id":3, "name":"Remove", "parentID":1 }, { "id":9, "name":"Update", "parentID":1 }, { "id":11, "name":"UpdateDel", "parentID":9 }, 
{ "id":27, "name":"Add", "parentID":2 }, { "id":28, "name":"master" } ]  ;
   this.persistedName = "MyItemsPersisted";
   this.treeViewName = "MyItemsTreeView";
  }

HomePage.html

  <ion-content>
  <div class="ion-padding">
The world is your oyster.
<p>If you get lost, the <a target="_blank" rel="noopener" href="https://ionicframework.com/docs/">docs</a> will be your guide.</p>
  </div>
  <tree-view [items]="items" [persistedName]="persistedName" 
   [treeViewName]="treeViewName"></tree-view>

</ion-content>

错误 enter image description here

2 个答案:

答案 0 :(得分:1)

如npm(https://www.npmjs.com/package/ionic-tree-view)所述,您需要将模块导入为IonicTreeViewModule.forRoot()

答案 1 :(得分:0)

您已经将导入依赖项的IonicTreeViewModule而不是IonTreeViewModule错了出来。