Error on click event of Tree component of PrimeNG -

喜你入骨 提交于 2019-12-13 03:46:43

问题


I'm getting a error on the click event of the Tree component of PrimeNG. I've followed everything as it is explained in the docs ( https://www.primefaces.org/primeng/#/tree). Worked just fine, except the click event. It doesn't drop the content..

- ERROR TypeError: eventTarget.className.indexOf is not a function -

Screenshot

Service:

getFiles() {
 let url = "https://raw.githubusercontent.com/primefaces/primeng/master/src/assets/showcase/data/files.json";
 return this.http.get(url)
  .toPromise()
  .then(res => <TreeNode[]> res.json().data);
}

component.ts

export class UsersComponent implements OnInit {

 files: TreeNode[];

 constructor(private userService: UserService,
          private httpClient: HttpClient, 
          private nodeService: NodeService) { }  

  ngOnInit() {
    this.nodeService.getFiles().then(files => this.files = files);
 }

  nodeSelect(event) {
    //event.node = selected node
    console.log("Event: "+event);
  }
}

and component.html:

<div class="container" style="margin: 2%">
   <div class="container" style="background-color: white"> 
       <ul> 
          <li *ngFor="let file of files">{{file.label}}</li>
       </ul>
   </div>

   <p-tree [value]="files" (onNodeSelect)="nodeSelect($event)"></p-tree>

Any thoughts? Thanks!


回答1:


Here I created a Stackblitz with your requirement. In this sample I used httpclient.

Once you select the node you can see the console log with related information. Better you can get this source to your local environment and test it.

Here is the primeng documentation.



来源:https://stackoverflow.com/questions/49984226/error-on-click-event-of-tree-component-of-primeng

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!