javascript - Angular7,获取 ElementRef
问题描述
我需要在子节点中获取 ElementRef。
我的模板
<div #charts *ngFor="let tag of _tags">
<jqxBulletChart
style="margin-left: 10px; float: left;"
[width]='50'
[height]='350'
[barSize]='"35%"'
[labelsFormat]='"c"'
[title]="''"
description="{{tag.configuration.name}}"
[showTooltip]='true'
[labelsFormatFunction]="labelsFormatFunction"
[tooltipFormatFunction]="tooltipFormatFunction" [ticks]='ticks'
[ranges]='tag.value'
[pointer]='pointer'
[orientation]="'vertical'"
>
</jqxBulletChart>
</div>
我打电话给
@ViewChildren('charts') infoCharts: ElementRef;
并得到孩子
for (let chart of this.arrCharts) {
console.log(chart);
console.log(chart.nativeElement.lastChild)
let child: jqxBulletChartComponent = chart.nativeElement.lastChild;
console.log(child);
console.log(+this.tags[count].displayValue);
child.val(+this.tags[count].displayValue || 0);
// child.val(20);
count++;
}
但我的“孩子”应该是 ElementRef 类型,我不知道该怎么做
解决方案
尝试这个 :
import {AfterViewInit, Component, QueryList, ViewChildren, ElementRef} from '@angular/core';
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"]
})
export class AppComponent {
name = "Angular";
@ViewChildren("charts") charts: QueryList<ElementRef>;
ngAfterViewInit() {
this.charts.forEach(c => console.log(c));
}
}
推荐阅读
- javascript - 无法使用 getDateTimeInstance 函数获取日期格式
- javascript - 将日期范围数组排序为组,其中每个组没有重叠范围(Javascript)
- vb.net - 我无法在 vb 2017 中定义列表?
- php - 即使设置了标头也会出现 CORS 错误 - 仅在某些调用中
- r - 使用 R 对两个数据帧进行多项操作
- vue.js - 如何在 Vue 中动态操作 DOM 并检测用户操作系统
- flutter - 使用上下文调用的 Mediaquery.of 不包含 mediaquery 错误
- python - 使用值在嵌套字典中获取与该值对应的键,该字典中每个键都有一个列表
- xml - XSLT 1.0 多个模板匹配块
- c# - 未验证最小起订量方法调用