Angular 6-nativeElement span类的@ViewChild访问值 [英] Angular 6 - @ViewChild Access value of nativeElement span class

查看:64
本文介绍了Angular 6-nativeElement span类的@ViewChild访问值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用@ViewChild是Angular.

I am using @ViewChild is 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);
  }

这什么都不返回.

我的问题是如何定位跨度的类并获取其价值?

My question is how to I target the span's class and get it's value?

推荐答案

您的查看子级应为:

@ViewChild("somename") somename: ElementRef;

那么你可以做:

this.somename.nativeElement.firstElementChild.innerHTML

这篇关于Angular 6-nativeElement span类的@ViewChild访问值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆