Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

How do you get AngularJS to bind to the title attribute of an A tag?

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."

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.

Ex. 1.

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

Expected result: <a title="Canon Powershot XS50 12MB Digital Camera" ...>

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

Ex. 2.

Code: <a ng-attr-title="{{product.shortDesc}}" ...>

Expected result: <a title="Canon Powershot XS50 12MB Digital Camera" ...>

Actual result: <a ng-attr-title="Canon Powershot XS50 12MB Digital Camera" ...>

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...