Search code examples
angularjsangularjs-material

AngularJS Material mdDialog and unhandled rejection on a promise


I have no idea why but I'm getting unhandled rejection error for AngularJS Material mdDialog on hide/cancel

Code for the mdDialog:

$scope.addAttendee = function(ev) {
    $mdDialog.show({
    controller: DialogController,
    templateUrl: 'views/regForm.tmpl.html',
    parent: angular.element(document.body),
    targetEvent: ev,
    clickOutsideToClose:true,
    controllerAs: 'ctrl',
    fullscreen: $scope.customFullscreen, // Only for -xs, -sm breakpoints.
    locals: {parent: $scope}
})
.then(function(response){
    if(angular.isDefined(response)){
        attendees.push(response);
    }

    console.log(attendees);
    console.log(attendees.length);
})

when I will remove a promise then the dialog box can be closed w/o error message.

Any clue what is going on with that?


Solution

  • It came that I need a function when there are no changes (hide/cancel) for a promise from mdDiaglog.

    Code after update

    $scope.addAttendee = function(ev) {
        $mdDialog.show({
        controller: DialogController,
        templateUrl: 'views/regForm.tmpl.html',
        parent: angular.element(document.body),
        targetEvent: ev,
        clickOutsideToClose:true,
        controllerAs: 'ctrl',
        fullscreen: $scope.customFullscreen, // Only for -xs, -sm breakpoints.
        locals: {parent: $scope}
    })
    .then(
        function(response){
            if(angular.isDefined(response)){
                attendees.push(response);
    
                console.log(attendees);
                console.log(attendees.length);
            }
        },
        function(){
            //no changes
        }
    )
    .catch(
        function(error) {
            console.error('Error: ' + error);
        }
    );