如何在角度2中动态地在输入框上添加工具提示

2024-05-27

我有一个输入框,我想在将鼠标悬停在输入框上时显示工具提示消息,这将基于我们从服务获得的响应。如果服务响应为“true”,则工具提示中的消息将为“true message”,如果服务返回 false,则该消息将为“false message”。

这是我的应用程序组件.html:

<div class="col-sm-8">
    <input class="form-control"
           type="text"
           [(ngModel)]="user.FormName">

          <button type="btn">Servicecall()</button>
</div>

应用程序组件.ts:

Servicecall(){
  if(serviceCallresponseIstrue)   
      //  success message on tooltip
  else {
      // error message on tooltip 
}
}

您可以使用 title="My tooltip" 标签向按钮添加一些工具提示。

现在,您可以使用模板创建动态工具提示:

<button title="{{tt}}"></button>

并在您的 ts 代码中设置工具提示:

tt: string;

Servicecall(){
  if(serviceCallresponseIstrue)   
      this.tt = "True tooltip";
  else {
      this.tt = "False tooltip"; 
  }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在角度2中动态地在输入框上添加工具提示 的相关文章

随机推荐