angularjs – AngularModalService:将数据传递给控制器

前端之家收集整理的这篇文章主要介绍了angularjs – AngularModalService:将数据传递给控制器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
没有太多的搜索.我在这里找到了一个类似的线程,但它对我来说并不适用.

这些示例表明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',function($scope) {

    $scope.close = function(result) {
        close(result,500); 
    };
}]);

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

解决方法

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

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

    $scope.close = function(result) {
        close(result,500); 
    };
}]);

猜你在找的Angularjs相关文章