0

$dialog ディレクティブを使用して、アプリケーションでダイアログを表示しています。ダイアログは別のディレクティブから開かれます:

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'
}
}]);

私が抱えている問題は、ダイアログのコントローラーから、呼び出し元のディレクティブのスコープにアクセスしたいということです。特に、上記のコードの「モデル」プロパティ。

解決を使用してみましたが、ダイアログ コントローラーからデータを取得する方法がわかりません。

何を変更すればよいですか?

4

1 に答える 1

1

ダイアログコントローラーでは、依存関係として追加するだけです。

あなたはそれを呼んだdataので、そうあるべきです-

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

余談ですが、$dialog を開く動作を、ディレクティブ内ではなくビュー コントローラーの外側に抽出します。これは、アプリケーション ロジックのように見え、ディレクティブは再利用可能にする必要があるためです。

于 2013-07-04T14:07:26.240 に答える