gpt4 book ai didi

Angular 6 - @ViewChild 访问 nativeElement 跨度类的值

转载 作者:搜寻专家 更新时间:2023-10-30 22:04:02 25 4
gpt4 key购买 nike

我正在使用 @ViewChild 是 Angular。

在我的 app.component.html 我有:

<div #somename>Mark<span class="somethingelse">Hello something else</span></div>

在我的 app.component.ts

@ViewChild('somename') SomeName;

constructor() {}

getInputValue() {
alert(this.SomeName.nativeElement('span').getElementByClassName('somethingelse').innerHTML);
}

这不会返回任何东西。

我的问题是如何定位 span 的类并获取它的值?

最佳答案

你的 View child 应该是:

@ViewChild("somename") somename: ElementRef;

然后你可以这样做:

this.somename.nativeElement.firstElementChild.innerHTML

关于Angular 6 - @ViewChild 访问 nativeElement 跨度类的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50644841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com