Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using the $dialog directive to show a dialog in my application. The dialog is opened from another directive :

angular.module('axa.directDebit.directives').directive("mandateHistoryDetail", ['$dialog', function($dialog) {
return {
    restrict: 'E',
    template: '<a class="btn btn-small" ng-click="openDialog()">Détail</a>',
    scope: {
        model: '='
    },
    link: function (scope, element, attrs) {
        scope.openDialog = function(){
            var d = $dialog.dialog({
                backdrop: true,
                keyboard: true,
                backdropClick: true,
                dialogFade: true,
                templateUrl: 'app/directDebit/views/mandates.detail.history.detail.html',
                controller: 'mandates.detail.history.detail.ctrl',
                resolve: {
                    data: function () {
                        return scope.model;
                    }
            }
            });
            d.open();
        }
    },
    controller: 'mandates.detail.history.detail.ctrl'
}
}]);

The problem I'm having, is that from the dialog's controller, I would like to access the calling directive's scope. In particular the 'model' property in the above code.

I've tried using resolve, but the from the dialog controller I don't know how to get hold of data.

Any idea what I should change ?

share|improve this question

1 Answer

up vote 1 down vote accepted

In the dialog controller, you should just add it as a dependency.

You called it data so it should be -

angular.module('yourModule').controller('mandates.detail.history.detail.ctrl', 
                                        function($scope, data){ 
 ...
});

Just as a side note - I would extract the behavior of opening the $dialog to an outside view controller and not inside a directive, 'cause it looks like application logic to me and directives should aspire to be reusable.

share|improve this answer
excellent. Thanks for your help ! – Sam Jul 5 at 7:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.