本文介绍了如何捕捉< mat-error>错误信息文本内容使用量角器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理以下元素,并且无法将错误消息文本输入到变量中.

I'm dealing with below element and having trouble with getting the error message text in to a variable.

<mat-error _ngcontent-c16="" class="mat-error ng-star-inserted" id="error-email-required" role="alert" style=""> Email is a required field </mat-error>

直接捕获元素.

我尝试了以下选项,但所有打印为>>可见的错误消息是:[object Object]

I tried below options but all printing as >> visible error message is : [object Object]

  • var errormsg = emailReqiredLabel.getText().toString();

  • var errormsg = emailReqiredLabel.getText().toString();

var errormsg = emailReqiredLabel.getAttribute('value').toString();

var errormsg = emailReqiredLabel.getAttribute('value').toString();

console.log(可见的错误消息是:" + errormsg);

console.log("visible error message is : " + errormsg );

有人可以请教吗.

推荐答案

mat-error默认情况下不显示.仅在触摸输入时显示.因此,在获取文本之前,请尝试单击该字段并尝试getText().如果这样不起作用,请尝试JSON.Stringify(errormsg).

mat-error does not show up by default. It only shows when the input is touched. So before getting the text try to click on the field and try getText(). If that does not work try JSON.Stringify(errormsg).

这篇关于如何捕捉&lt; mat-error&gt;错误信息文本内容使用量角器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 01:27