Angular Material : Custom Dialog Service

Standard

Customize Angular dialogue service, register within your controller and other data services and use it throughout your project. For html code clone my repo from github.

Github Link

Angular Code:

(function () {
    'use strict';

    var app = angular.module('app', ['ngMaterial']);

    app.controller('dialogController', function (confirmAlert) {

        var vm = this;
        
        vm.confirm= function () {
            confirmAlert.confirmBoxResponse(
                'Would you like to delete?',
                'Record will be deleted ',
                'Delete',
                callBack,
                "Hello World");
        };

        function callBack(param) {
            vm.result = param;
        }

    });

})();

Toaster Service:

(function () {
    'use strict';

    angular
        .module('app')
        .factory('confirmAlert', confirmAlert);

    confirmAlert.$inject = ['$mdDialog'];

    function confirmAlert($mdDialog) {

        var service = {
            confirmBoxResponse: confirmBoxResponse
        };

        return service;

        ////////////////////////////Implementation//////////////////////////////////////

        function confirmBoxResponse(title, content, confirmText, successCb, successCbParam) {
            var confirm = $mdDialog.confirm()
                      .title(title)
                      .textContent(content)
                      .ariaLabel('Lucky day')
                      .ok(confirmText)
                      .cancel('Cancel');

            $mdDialog.show(confirm).then(function () {
                successCb(successCbParam);
            }, function () {
                //pressed cancel
            });
        }

    }

})();

Output:

Screenshot_2

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s