如果你有 1 个按钮,它应该像这样简单:
单个按钮的角度
var app = angular.module("myApp", []);
app.controller("myCtrl", ["$scope", function ($scope) {
$scope.hideBorder = false;
$scope.toggleBorder = function () {
$scope.hideBorder = !$scope.hideBorder;
}
}]);
单个按钮的 HTML
<button class="{{hideBorder ? 'button--no-bottom-border': ''}}" ng-click="toggleBorder()">Click Me</button>
CSS
button {
border: 1px solid black;
outline: none;
}
.button--no-bottom-border {
border-bottom: 0px;
}
如果你有多个按钮,你的 Angular 和 HTML 会略有变化:
多个按钮的角度
$scope.toggleBorder = function (button) {
button.hideBorder = !button.hideBorder;
}
$scope.buttons = [
{
text: "Click Me",
hideBorder: false
},
{
text: "Click Me 2",
hideBorder: false
},
{
text: "Click Me 3",
hideBorder: false
},
];
多个按钮的 HTML
<button class="{{button.hideBorder ? 'button--no-bottom-border': ''}}" ng-click="toggleBorder(button)" ng-repeat="button in buttons">Click Me</button>