你怎么AngularJS绑定到一个标记的title属性? [英] How do you get AngularJS to bind to the title attribute of an A tag?
问题描述
这样做的目的是有一个产品的名字出现在缩略图的提示。
浏览器不创建NG标题或工具提示NG-ATTR-称号。
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。
您可以prePEND以NG-或NG-ATTR任何属性和角度会相应绑定。然而,这似乎并没有绑定到HTMLA标记的标题attirbute。
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。
code:<标题={{product.shortDesc}}...>
预期结果:<标题=佳能XS50 12MB数码相机......>
实际结果:<标题={{product.shortDesc}}...>
我们得到的提示不需要的括号
Actual result: <a title="{{product.shortDesc}}" ...>
We get undesired braces in the tooltip.
前。 2。
code:&LT;一个NG-ATTR标题={{product.shortDesc}}...&GT;
预期结果:&LT;标题=佳能XS50 12MB数码相机......&GT;
实际结果:&LT;一个NG-ATTR标题=佳能XS50 12MB数码相机......&GT;
我们没有得到一个简单的标题
attirbute,也没有得到一个工作提示。
We do not get a plain title
attirbute, nor do we get a working tooltip.
推荐答案
看起来 NG-ATTR
是AngularJS 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.
<一个href=\"https://github.com/angular/angular.js/commit/cf17c6af475eace31cf52944afd8e10d3afcf6c0\">https://github.com/angular/angular.js/commit/cf17c6af475eace31cf52944afd8e10d3afcf6c0
不过,如果你留在1.0.7,你也许可以写一个自定义指令镜面的效果。
However, if you stay with 1.0.7, you can probably write a custom directive to mirror the effect.
<!-- example -->
<a ng-attr-title="{{product.shortDesc}}"></a>
这篇关于你怎么AngularJS绑定到一个标记的title属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!