【问题标题】:How to use $materialDialog如何使用 $materialDialog
【发布时间】:2014-09-03 11:05:47
【问题描述】:

$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

【问题讨论】:

  • 如果您提供示例作为 plunker 会很好
  • This?我的代码是一样的,看demo,就是destroyDialog对话框

标签: angularjs material-design


【解决方案1】:

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

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

【讨论】:

    【解决方案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 内传递

    【讨论】:

      猜你喜欢
      • 2017-04-22
      • 1970-01-01
      • 1970-01-01
      • 2014-12-05
      • 1970-01-01
      • 2022-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多