如何在页面加载时突出显示mat树的几个节点?

时间:2019-09-26 09:47:37

标签: javascript typescript angular-material angular7

以下提供的代码用于突出显示mat树的节点,但是如何在页面加载时默认使某些节点突出显示?

updateHighlight = (newHighlight: ElementRef) => {

  this.renderer.addClass(newHighlight.nativeElement, 'style');
  this.newtarget=newHighlight.nativeElement.offsetParent.innerText;
  if(this.oldHighlight!=undefined)
  {
    console.log(JSON.stringify(newHighlight.nativeElement.value)); 

    this.renderer.addClass(newHighlight.nativeElement, 'style');
  }
  else{
    this.oldHighlight && this.renderer.removeClass(this.oldHighlight.nativeElement, 'style');
  }

  this.renderer.addClass(newHighlight.nativeElement, 'style');

  this.oldHighlight = newHighlight;
}

ngAfterViewChecked() {
  this.treeControl.expand(this.treeControl.dataNodes[4])
  this.treeNodes.forEach((reference) => {
    if (!this.hasListener.includes(reference.nativeElement)) {

      console.log('* tick');

      this.renderer.listen(reference.nativeElement, 'click', () => {

        this.updateHighlight(reference);
      });
      this.hasListener = this.hasListener.concat([ reference.nativeElement ]);
    }
  });

  this.hasListener = this.hasListener.filter((element) => document.contains(element));
  console.log('*', this.hasListener.length);
}

enter image description here

0 个答案:

没有答案