Javascript 可执行角度指令上的2个取消按钮

Javascript 可执行角度指令上的2个取消按钮,javascript,angularjs,x-editable,Javascript,Angularjs,X Editable,我用的是角度指令。你能告诉我如何使用2个取消按钮吗?因为我需要在上面实现两个功能。我的意思是cancel+mywork1和cancel+mywork2。提前谢谢 HTML <form editable-form name="tableform" onaftersave="saveTable()" oncancel="cancel()"> //UI code here <button type="button" ng-disabled="tableform.$waiting"

我用的是角度指令。你能告诉我如何使用2个取消按钮吗?因为我需要在上面实现两个功能。我的意思是
cancel+mywork1
cancel+mywork2
。提前谢谢

HTML

<form editable-form name="tableform" onaftersave="saveTable()" oncancel="cancel()">

//UI code here

<button type="button" ng-disabled="tableform.$waiting" ng-click="tableform.$cancel()" class="btn btn-default">Cancel</button>

</form>

实际上,您应该能够控制取消按钮的功能。如果仔细研究代码,您会发现,它们只是创建一些按钮,并根据当前表单状态(form.$visible)显示或隐藏它们

  //html
  <button type="button" ng-disabled="tableform.$waiting" ng-click="cancel1(tableform)" class="btn btn-default">cancel 1</button>
  <button type="button" ng-disabled="tableform.$waiting" ng-click="cancel2(tableform)" class="btn btn-default">cancel 2</button>

  //controller
  $scope.cancel1 = function(tableForm) {
    // Call tableForm cancel to reset
    tableForm.$cancel();
    //Logic1
  };

  $scope.cancel2 = function(tableForm) {
    // Call tableForm cancel to reset
    tableForm.$cancel();
    //Logic2
  };
像这样做

 <button type="button" ng-disabled="tableform.$waiting" ng-click="tableform.$cancel()" class="btn btn-default">cancel1</button>
    </div> 
cancel1

这是一个

在表单中可以有两个取消按钮,并将表单作为属性传递。然后在相应的cancel函数中,您可以调用form.$cancel,然后执行逻辑<代码>表单。$cancel的工作与调用
ng click=“tableform.$cancel()”
的工作相同

玩它:

//html
取消1
取消2
//控制器
$scope.cancel1=函数(表格形式){
//调用tableForm cancel重置
tableForm.$cancel();
//逻辑1
};
$scope.cancel2=函数(表格形式){
//调用tableForm cancel重置
tableForm.$cancel();
//逻辑2
};

如何根据您的示例为一个事件提供两个功能?您仅使用了
oncancel
事件。我需要对这些事件实施两种方法或行为(即,在2个取消事件上)。在这种情况下,我认为您可能必须为每个span创建一个带有名称的电子表单,以便您可以为每个表单访问$cancel方法否。这样它就不起作用了。因为我需要使用两个
cancel
按钮访问同一表单的属性。不能使用两个表单。
  //html
  <button type="button" ng-disabled="tableform.$waiting" ng-click="cancel1(tableform)" class="btn btn-default">cancel 1</button>
  <button type="button" ng-disabled="tableform.$waiting" ng-click="cancel2(tableform)" class="btn btn-default">cancel 2</button>

  //controller
  $scope.cancel1 = function(tableForm) {
    // Call tableForm cancel to reset
    tableForm.$cancel();
    //Logic1
  };

  $scope.cancel2 = function(tableForm) {
    // Call tableForm cancel to reset
    tableForm.$cancel();
    //Logic2
  };