AngularModalService:将数据传递给控制器

kis*_*tic 4 modal-dialog angularjs angular-ui-bootstrap

没有太多的搜索.我在这里找到了一个类似的线程,但它对我来说并不适用.

这些示例表明Modal将获得一个单独的控制器.看起来像这样.

var app = angular.module('myApp', ['ngSanitize','angularModalService']);
app.controller('SampleController', ['$scope', function($scope) {

    $scope.showAlert = function() {

        ModalService.showModal({
            templateUrl: "alertWindow.html",
            controller: "AlertController",
            inputs: {
                title: "Add New Alert",
            }
        }).then(function(modal) {
            modal.element.modal();
            modal.close.then(function(result) {
                $scope.result = "blah";
            });
        });

     });
}]);

app.controller('AlertController', ['$scope', function($scope) {

    $scope.close = function(result) {
        close(result, 500); 
    };
}]);
Run Code Online (Sandbox Code Playgroud)

我需要注意的是,我希望模态对话框具有SampleController中的一些默认值.我读了服务,但我认为这不起作用.输入:showModal()中的{}看起来很可疑,但是一旦显示模态窗口,我就不确定从哪里获取它.我见过的其他例子只显示简单的是/否按钮或文本输入w /空默认值.

小智 7

根据文档,您将输入注入模态控制器.由于title是您在上面提到的输入,因此您可以将模态控制器更改为:

app.controller('AlertController', ['$scope', 'title', function($scope, title) {
    $scope.title = title;

    $scope.close = function(result) {
        close(result, 500); 
    };
}]);
Run Code Online (Sandbox Code Playgroud)