How to access a method in a Javascript Function at the angle?

Asked

Viewed 151 times

1

I am using a plugin in Jquery and it works very well in Angular, however I want to call a service method within a function of an alert, follows below the code:

click event that creates the modal

<button class="button small alert" (click)="didTouchDeleteBrand(brand)"><span class="mif-bin"></span> Excluir</button>

method that displays the modal and when clicking yes it generates the error

ERROR TypeError: Cannot read property 'brandService' of undefined

code:

  constructor(private router: Router, private brandService: BrandService) {}

  public didTouchDeleteBrand(brand: Brand) {

function removeItem(teste){
  this.brandService.deleteBrand(teste.BrandID).subscribe(
    () => { 
      this.loadTableContent('');
    },
    (err) => { console.log(err); 
    }
  );
}
Metro4.dialog.create({
  title: "Confirmação de exclusão",
  content: "<div>Deseja realmente excluir este item?</div>",
  actions: [
      {
          caption: "Sim",
          cls: "js-dialog-close alert",
          onclick: function(){
            console.log(brand.BrandID);
            removeItem(brand.BrandID);
          }
      },
      {
          caption: "Cancelar",
          cls: "js-dialog-close"
      }
  ]
});
}
  • Why do you declare one method within another? Declares it in its component and calls using this.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.