【发布时间】:2016-08-19 19:40:34
【问题描述】:
我希望我的按钮在单击时改变颜色。也只需更改 3 秒钟,然后返回默认颜色。我一直在查看有关堆栈溢出的类似问题 postet,但无论我尝试过什么都不起作用(不知道为什么我的代码不起作用)。另外我不知道如何让它改变颜色只有 3 秒。 到目前为止我 1. $scope.isActive=false; 2.然后在控制器里,我把它改成true if clicked:
$scope.copyText = function(text){
$scope.isActive = !$scope.isActive;
console.log('clicked in controller');
Clipboard.copy(text)
}
html:
<div class="inner-single" ng-hide="updateInfo">
<h3>Login Details:</h3>
<h5 ><span class="categories">Username:</span> {{account.username}}<button
ng-click="copyText(account.username)" ng-class="isActive ? 'noColor' : 'hasColor'" >
Copy</button></h5>
<button class="btn btn-large btn-default" ng-click="showForm()">Update Info</button>
CSS
.copy-button {
.copy-button.hasColor {
color:green;
}
.copy-button.noColor {
color: grey; }
font-size: 12px;
padding: 0px, 3px, 0px, 3px;
margin-left: 5px; }
}
为了跟踪秒数,我会使用 setTimeout 函数,但是不确定如何将它与 angular 结合并更改颜色..
对建议感到满意! 谢谢!
【问题讨论】:
标签: angularjs settimeout ng-class