[英]How can I make a button title equal to a value on my scope?
I have a button inside of an ng-repeat div on my template, and I would like to set it's title property to be equal to a value from my scope, but it is showing up as the string, not the value. 我的模板上的ng-repeat div内有一个按钮,我想将其title属性设置为与我的作用域中的值相等,但它显示为字符串而不是值。
template: 模板:
<div ng-repeat="step in steps">
<button title="step.description">Text</button>
</div>
On hover, the above displays the literal string "step.description" instead of the value from my scope. 悬停时,上面显示的是文字字符串“ step.description”,而不是我的作用域中的值。 Currently my controller has an array on it called steps, and each of the step objects in that array has a key named "description" set to a different string.
当前,我的控制器上有一个名为step的数组,该数组中的每个step对象都有一个名为“ description”的键,该键设置为不同的字符串。
I think this link can help you. 我认为此链接可以为您提供帮助。 How do you get AngularJS to bind to the title attribute of an A tag?
如何使AngularJS绑定到A标签的title属性?
<body ng-app="myApp">
<div ng-controller="myCtrl">
<div ng-repeat="step in steps">
<button ng-attr-title="{{step.description}}">Text</button>
</div>
</div>
</body>
You can use ng-attr-title
to bind value on hover. 您可以使用
ng-attr-title
将鼠标悬停时绑定值。 ng-attr
is a new directive in AngularJS 1.1.4 ng-attr
是AngularJS 1.1.4中的新指令
app.controller('myCtrl', ['$scope', function($scope){
$scope.steps = [
{
description: 'Test1'
},
{
description: 'Test2'
},
{
description : 'Test3'
}
];
Here is the link: https://plnkr.co/edit/Ql4GHSkcuD1r9SywL2mi?p=preview 这是链接: https : //plnkr.co/edit/Ql4GHSkcuD1r9SywL2mi?p=preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.