<html>

<head>
    <title>Angular Toast Service</title>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.2/toastr.min.js"></script>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.min.js"></script>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-animate.min.js"></script>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-loader.min.js"></script>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-sanitize.min.js"></script>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-cookies.min.js"></script>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-touch.min.js"></script>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-resource.min.js"></script>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.12.1/ui-bootstrap.min.js"></script>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.12.1/ui-bootstrap-tpls.min.js"></script>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.13/angular-ui-router.min.js"></script>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui/0.4.0/angular-ui-ieshiv.min.js"></script>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui/0.4.0/angular-ui.min.js"></script>

    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.1/toastr.min.css">
    <link rel="stylesheet" type="text/css" href="style.css">

    <script type='text/javascript' src="script.js"></script>
    <script type='text/javascript' src="https://rawgit.com/long2know/angular-services-general/master/src/toastService.js"></script>
</head>

<body ng-app="myApp">
    <div ng-controller="myCtrl as vm">
        <button ng-click="vm.openSimpleToast()">Open Simple</button>
        <button ng-click="vm.openInteractiveToast()">Open Interactive (Compiled)</button>
        <br />
        <h3>Toast Service</h3>
        <pre ng-bind="vm.times | json"></pre>
    </div>
</body>

<script type="text/ng-template" id="toastTemplate.html">
    <div class="toast-title" ng-bind-html="tc.message" />
    <div class="toast-message">
        <span>Click Ok to clear the errors.</span>
        <button id="toastClose" class="btn btn-primary" ng-click="tc.ok(tc.toast)">Ok</button>
    </div>
</script>

</html>
small {
    font-size: 0.625em;
    font-style: italic;
    color: #a94442;
    display: block;
    float:right;
}

input {
    display:block !important;
}

label {
    display:block;
}

.container {
    width: auto !important;
}

.form-inline .form-group {
    display:inline-block;
    width: auto;
}

input {
    width: 250px !important;
}
(function () {
    angular.module('myApp.services', ['ngResource', 'ngAnimate']);
    angular.module('myApp.controllers', []);

    var myApp = angular.module('myApp', [
        'myApp.services',
        'myApp.controllers',
        'long2know',
        'ngSanitize',
        'ui.bootstrap',
        'ui']);

    var toastCtrl = function ($sce, toastData) {
        var vm = this,
            initialize = function () {
                vm.message = $sce.trustAsHtml(toastData.message);
            };

        vm.ok = function () {
            toastData.sharedData.time = new Date().getTime();
            toastData.closeToast();
        };

        initialize();
    };

    toastCtrl.$inject = ['$sce', 'toastData'];
    angular
        .module('myApp.controllers')
        .controller('toastCtrl', toastCtrl);

    var myController = function ($log, toastSvc) {
        var
            vm = this,
            closeToast = function (toast) {
                toast.close();                
                // Perform whatever other processing we need to on the resolves..
                $log.log('Return data: ' + vm.sharedData.time);
              vm.times.push(vm.sharedData.time);
            };

        vm.times = [];
        vm.sharedData = {
            time: new Date().getTime()
        };
        
        vm.openSimpleToast = function () {
            toastSvc.success("I'm a simple toast");
        }

        vm.openInteractiveToast = function () {
            var message = "I'm a complex toast.";
            var toast = toastSvc.render({
                templateUrl: 'toastTemplate.html',
                controller: 'toastCtrl as tc',
                resolves: {
                    toastData: function () {
                        return {
                            closeToast: function () {
                                closeToast(toast);
                            },
                            message: message,
                            sharedData: vm.sharedData
                        };
                    }
                }
            });
        }
    };

    myController.$inject = ['$log', 'toastService'];
    angular.module('myApp.controllers')
        .controller('myCtrl', myController);

    myApp.config(['$locationProvider',
        function ($locationProvider) {
            $locationProvider.html5Mode(false);
        }]);

    myApp.run(['$log', function ($log) { $log.log("Start."); }]);
})()

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.