0

$materialDialogAngular Material Design组件。
但是如何使用该组件?为什么它不返回 angular-ui bootstrap 之类的东西?如何检索承诺或结果或其他任何东西,只是关闭模式?这是一个简短的例子:

var test = $materialDialog({
        templateUrl: '/Assets/app/azured/partials/dialog.html',
        targetEvent: event,
        resolve:{
            item: function () {
                return item;
            }
        },
        appendTo: angular.element.find('dialog'),
        controller: ['$scope', '$hideDialog', 'item', function ($scope, $hideDialog, item) {
            $scope.name = item.Name;
            $scope.cancel = function () {
                $hideDialog();
            }
            $scope.ok = function () {
                scope.name = '';
                $hideDialog();
            };
        }]
    });
    test.then(function (x) {
        console.log(x); //this prints destroyDialog function why?
    });

我们从哪里知道用户按下了什么?我应该在 $materialDialog 中实现自定义逻辑吗?在那种情况下,我觉得很奇怪。github 237中的问题

4

2 回答 2

4

这是一篇博客文章,展示了一种更简洁的方法并包含一个 Plunker。

http://angularauthority.com/2015/04/28/creating-a-material-design-modal-service/

于 2015-04-28T23:43:47.340 回答
2

像这样解决

function DeleteItem(_list, _item) {
    azuredBlade.Load('listId');
    Api.Delete(_list, _item).then(function (x) {
        if (x) {
            azuredBlade.Deload('listId');
            Refresher();
        }
    });
}
function Dialog(event, item, tableName) {
    $materialDialog({
        templateUrl: '/Assets/app/azured/partials/dialog.html',
        targetEvent: event,
        resolve: {
            item: function () {
                return item;
            },
            tableName: function () {
                return tableName;
            },
            fn: function () {
                return DeleteItem;
            }
        },
        appendTo: angular.element.find('dialog'),
        controller: function ($scope, item, tableName, $hideDialog, fn) {
            $scope.name = item.Name;
            $scope.cancel = function () {
                $hideDialog();
            }
            $scope.ok = function () {
                fn(tableName, item);
                $hideDialog();
            };
        }
    });
}

所以逻辑在 $materialDialog 之外并在内部传递fn resolve

于 2014-09-04T04:57:07.303 回答