我正在使用 @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/