How to add SweetAlerts to your page

SweetAlerts are used to show a popup to the user in various situations - while the page loads, after a successful action, after a failed action, and more. Getting started with SweetAlert in the Medium One portal is simple.

 

1. Inject "SweetAlert" into your controller or directive.

angular.module('Module', []).controller('TestSwal', TestSwal)

TestSwal.$inject = ['SweetAlert']

function TestSwal(SweetAlert) {
}

2. Add a SweetAlert in your controller or directive.

swal("test")

 

Example Code

HTML:

<div ng-controller="TestSwal as ctr">
</div>

JS:

angular.module('Module', []).controller('TestSwal', TestSwal)

TestSwal.$inject = ['SweetAlert']

function TestSwal(SweetAlert) {
swal("test")
}

RESULT:

mceclip0.png

 

Resources

For more information on SweetAlert, check out their docs here.