代码之家  ›  专栏  ›  技术社区  ›  Chanaka Amarasinghe

如何在Angular2/4中使用具有相同单击事件的两个函数?

  •  -2
  • Chanaka Amarasinghe  · 技术社区  · 6 年前

    我有两个函数调用addshop()和saveshop()。但我只有一个按钮。这意味着只有一个点击事件。举个例子

    (click)=something();
    

    所以我需要在两个不同的时间内,在同一个点击事件中触发addshop和saveshop函数。有点像我需要用的其他东西。

    3 回复  |  直到 6 年前
        1
  •  0
  •   Chanaka Amarasinghe    6 年前
    (click)="variable==true ? addShop() : saveShop()"
    

    我们可以在两个不同的时间将true和false传递给变量。如果它是真的fire addshop(),如果它是假的fire saveshop()。

        2
  •  -1
  •   Taranjeet Singh    6 年前

    function confirmDelete() {
    //do stuff of this functions
    //delete process
    
    //execute other fucntion here
    otherFunction()
    }
    
    function otherFunction() {
    //some other funcitons
    }
              <div class="btn btn-danger" id="confirmForDelete" (click)="confirmDelete()" translate>Confirm</div>
        3
  •  -1
  •   maha    6 年前

    生成一个调用两个函数的函数,并在单击时执行该函数:

    (click)="executeBoth()"
    

    TS:

      executeBoth() {
          function1();
          function2();
      }