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.
– Eduardo Vargas