如何让 AngularJS 绑定到 A 标签的 title 属性? [英] How do you get AngularJS to bind to the title attribute of an A tag?

查看:57
本文介绍了如何让 AngularJS 绑定到 A 标签的 title 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目的是让产品名称出现在缩略图的工具提示中.浏览器不会根据ng-title"或ng-attr-title"创建工具提示.

The intent is to have a product name appear in the tooltip of a thumbnail. Browsers do not create a tooltip from "ng-title" or "ng-attr-title."

我们使用的是 AngularJS 1.0.7 版.您可以在任何属性前加上ng-"或ng-attr",Angular 将相应地绑定.但是,它似乎没有绑定"到 HTMLA"标签的标题属性.

We are using AngularJS version 1.0.7. You can prepend any attribute with "ng-" or "ng-attr" and Angular will bind accordingly. However, it doesn't seem to "bind" to the title attirbute of the HTML "A" tag.

例如.1.

代码:<a title="{{product.shortDesc}}" ...>

预期结果:

实际结果:<a title="{{product.shortDesc}}" ...> 我们在工具提示中得到了不需要的大括号.

Actual result: <a title="{{product.shortDesc}}" ...> We get undesired braces in the tooltip.

例如.2.

代码:

预期结果:

实际结果:

我们没有获得简单的 title 属性,也没有获得有效的工具提示.

We do not get a plain title attirbute, nor do we get a working tooltip.

推荐答案

看起来 ng-attrAngularJS 1.1.4,你可以在这种情况下使用.

It looks like ng-attr is a new directive in AngularJS 1.1.4 that you can possibly use in this case.

<!-- example -->
<a ng-attr-title="{{product.shortDesc}}"></a>

但是,如果您继续使用 1.0.7,您可能可以编写自定义指令来反映效果.

However, if you stay with 1.0.7, you can probably write a custom directive to mirror the effect.

这篇关于如何让 AngularJS 绑定到 A 标签的 title 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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