There are a few simple libraries to make Angular work with Sweetalert. If you really want to check them out:
Unfortunately, they wern't that "Sweet". The idea is to not use libraries to use other libraries.
Here is a simple module that anyone can write around Sweetalert, to make things work.
# sweetalert.coffee
do ->
'use strict'
SweetAlert = ->
return window.swal
angular
.module('sweetalert', [])
.factory('swal', SweetAlert)
Simply include sweetalert
in your app.js
or app.coffee
.
# app.coffee
do ->
'use strict'
angular.module('yourApp', ['sweetalert'])
Usage
Once setup, you can simply call sweetalert by calling swal
.
do ->
'use strict'
DemoController = ($scope) ->
$scope.btnClickHandler = ->
swal('Hello, World!')
angular
.module('demo', ['sweetalert'])
.controller('DemoController', DemoController)
You just saved yourself from adding an extra library to run another library. :beers:
Nice, I've used a similar method to access underscore.
Note - Since you didn't dependency inject swal into 'DemoController', you're using the reference on window..