如何使按钮标题等于范围内的值?
How can I make a button title equal to a value on my scope?
我的模板上的 ng-repeat div 中有一个按钮,我想将它的标题 属性 设置为等于我范围内的值,但是它显示为字符串,而不是值。
模板:
<div ng-repeat="step in steps">
<button title="step.description">Text</button>
</div>
悬停时,上面显示的是文字字符串 "step.description" 而不是我范围内的值。目前我的控制器上有一个名为 steps 的数组,并且该数组中的每个步骤 objects 都有一个名为 "description" 的键设置为不同的字符串。
我认为这个 link 可以帮助你。 How do you get AngularJS to bind to the title attribute of an A tag?
<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>
您可以使用 ng-attr-title
在悬停时绑定值。ng-attr
是 AngularJS 1.1.4
中的新指令
app.controller('myCtrl', ['$scope', function($scope){
$scope.steps = [
{
description: 'Test1'
},
{
description: 'Test2'
},
{
description : 'Test3'
}
];
这里是link:https://plnkr.co/edit/Ql4GHSkcuD1r9SywL2mi?p=preview
我的模板上的 ng-repeat div 中有一个按钮,我想将它的标题 属性 设置为等于我范围内的值,但是它显示为字符串,而不是值。
模板:
<div ng-repeat="step in steps">
<button title="step.description">Text</button>
</div>
悬停时,上面显示的是文字字符串 "step.description" 而不是我范围内的值。目前我的控制器上有一个名为 steps 的数组,并且该数组中的每个步骤 objects 都有一个名为 "description" 的键设置为不同的字符串。
我认为这个 link 可以帮助你。 How do you get AngularJS to bind to the title attribute of an A tag?
<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>
您可以使用 ng-attr-title
在悬停时绑定值。ng-attr
是 AngularJS 1.1.4
app.controller('myCtrl', ['$scope', function($scope){
$scope.steps = [
{
description: 'Test1'
},
{
description: 'Test2'
},
{
description : 'Test3'
}
];
这里是link:https://plnkr.co/edit/Ql4GHSkcuD1r9SywL2mi?p=preview