一种方法是使用ng-show 和ng-hide 设置两个按钮并根据您的应用程序状态显示/隐藏它们。举例:
%button.unlink{"ff-profile-unlink" => "true", "ng-show" => "linked_to_facebook", "ng-click" => "unlink_facebook"} Unlink Facebook
%button.unlink{"ff-profile-link" => "true", "ng-hide" => "linked_to_facebook", "ng-click"="link_facebook"} Link Facebook
然后
function SomeCtrl ($scope) {
$scope.link_facebook: function() { $scope.linked_to_facebook = true},
$scope.unlink_facebook: function() { $scope.linked_to_facebook = false},
}
另一种方法是使用 CSS 来实现相同的结果。这里的逻辑是有两个按钮,每次隐藏/显示一个,使用 CSS。这是一个例子:
%div#links
%button.unlink{"ff-profile-unlink" => "true"} Unlink Facebook
%button.link{"ff-profile-link" => "true"} Link Facebook
在你的 SASS 中:
.linked_to_facebook {
.link { display: hidden}
.unlink {display: block}
}
.unlinked_from_facebook {
.link { display: block}
.unlink {display: hidden}
}
然后您将使用addClass 和removeClass 将linked_to_facebook 和unlinked_from_facebook 添加和删除到#links div。
P.S:上面的代码可以改进。只是为了说明问题。