简体   繁体   English

重命名按钮 angular 9 内的函数名称

[英]Rename function's name inside button angular 9

On change select's function... Depending on the selected option, I want to rename the 'functionX' dynamically... Frontend更改选择的功能...根据所选选项,我想动态重命名“functionX”...前端

<select [(ngModel)]="selectedOp" (change)="selectedOption()">
   <option value={{op}} *ngFor="let op of Options">{{op}}</option>>
</select>

<button id="btnID" type="submit" (click)="functionX()">
 Button
</button>

Backend后端

I've been trying this using js...我一直在尝试使用js...

Options = ['Function1', 'Function2'];

selectedOp;

selectedOption(){
    switch (this.selectedOp) {
      case 'Function1':
          const btn = document.getElementById('btnID');
          btn.setAttribute('(click)', 'function1()');
      break;
      case 'Function2':
          const btn = document.getElementById('btnID');
          btn.setAttribute('(click)', 'function2()');
      break
}

Then this error happens...然后这个错误发生...

ERROR DOMException: Failed to execute 'setAttribute' on 'Element': '(click)' is not a valid attribute name..

If you guys know of a better way to do this, I'd appreciate your sharing :)如果你们知道更好的方法来做到这一点,我很感激你的分享:)

selectedOption(){
switch (this.selectedOp) {
  case 'Function1':
      this.funciton1();
  break;
  case 'Function2':
      this.function2();
  break
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM