Implementing sweet alert for displaying alert messages in angularJS2/typescript. Due to the repetitive nature of this code in different parts of the application, a service was created.
@Injectable()
export class AlertMessageService {
constructor(private http: Http) {
}
public deleteMessage(){
return swal({
title: 'Are you sure?',
text: "Delete the selected record(s)?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#66c378',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes'
})
}
Attempting to use the service in a component as shown below, but encountering issues.
this.alertMessageService.deleteMessage.then(() => {
if (ind !== -1 && ind != undefined) {
this.attachments.splice(ind, 1);
}
/* let headers = new Headers();
this.http.delete(AppUtils.INCIDENT_ATTACHMENT_URI+"/? path" + "=" + item.filePath, {})
.map(response => response.json().result)
.catch(this.handleError);*/
});
}
Is there a way to define different types of alerts within the service and inject them when needed? If so, how can this be achieved?