更改一些代码格式(angularJS 到 javascript)

Change a few code format (angularJS to javascript)

我正在学习 javascript 和 AngularJS。我为某些东西制作了这个小代码(我们以 AngularJS 格式制作),我们需要制作相同的逻辑但仅使用 javascript.

按钮的颜色会在可用或不可用时变为其他颜色。

有人可以帮我解决这个问题并告诉我其中的逻辑吗?

$scope.saveButton= function(){
  $( "#saveButtonPics" ).removeClass( "attachment-space-available" ).addClass( "attachment-boton-guardado" );
};

它不是 Angular 而是 jQuery 除了 $scope 我猜它是某些 Angular scope

的一部分

纯 JS 版本可以是

const saveButton = () => { 
  const cl = document.getElementById("saveButtonPics").classList;
  cl.remove("attachment-space-available")
  cl.add("attachment-boton-guardado");
};

如果你想链接,看看

const classList = elt => {
  const list = elt.classList;
  return {
    toggle: function(c) { list.toggle(c); return this; },
    add:    function(c) { list.add   (c); return this; },
    remove: function(c) { list.remove(c); return this; }
  };
};

const saveButton = () { 
  classList(document.getElementById("saveButtonPics"))
    .remove("attachment-space-available")
    .add("attachment-boton-guardado");
};

在angularjs中我们需要改变模型来改变视图

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">


<button ng-click="saveButton()" ng-class="savebtnclass">Save Pics</button>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.savebtnclass = "attachment-space-available";
    $scope.saveButton=function(){
        $scope.savebtnclass = "attachment-boton-guardado";
    }
});
</script>

</body>
</html>