【问题标题】:How to Add icon on dialogue in angular-material如何在角度材料中的对话上添加图标
【发布时间】:2016-06-13 12:32:22
【问题描述】:

我在我的项目中使用 Angular-material。我想在哪里显示我正在使用的对话

var confirm = $mdDialog.confirm()
            .title(modalObject.header)
            .content(modalObject.text)
            .ok(modalObject.control)
        $mdDialog.show(confirm).then(function () {
            var status = 'You decided to get rid of your debt.';
        }, function () {
            status = 'You decided to keep your debt.';
        });

我的要求是我必须在任何地方使用带有标题或内部正文的图标来显示此对话的用途。 例如:错误、警告和成功

但我无法做到这一点。

谁能告诉我如何解决它。

【问题讨论】:

    标签: angularjs modal-dialog angular-material mddialog


    【解决方案1】:

    你必须将它包含在一个函数中......就像......

        $scope.showConfirm = function (ev){
    
    var confirm = $mdDialog.confirm()
                .title(modalObject.header)
                .content(modalObject.text)
                .ok(modalObject.control)
            $mdDialog.show(confirm).then(function () {
                var status = 'You decided to get rid of your debt.';
            }, function () {
                status = 'You decided to keep your debt.';
            });
    
    };
    

    并通过 HTML 调用它。喜欢ng-click="showConfirm()"

    或者通过$scope.showConfirm();从控制器内部调用函数

    确保为您的内容分配了正确的控制器。

    【讨论】:

    • 感谢您的回复,但请再次阅读问题,我问了不同的问题。我的问题是如何将图标放在对话正文中,而不是如何调用或如何显示对话
    【解决方案2】:

    由于某种原因,md-dialog 的 title 和 textContent 没有绑定到 Html。另一种方法是使用模板选项并明确地将图标添加到您的模板:

    $mdDialog.show({
      scope: $scope,        
      preserveScope: true,           
      template: '<md-dialog>' +
                  '  <md-dialog-content>' +
                  '     <i class="fa fa-cloud"></i>{{modalObject.text}} -With icon' +  //Icon
                  '  </md-dialog-content>' +
                  '</md-dialog>'                 
      }
    }); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-10
      • 2018-06-17
      • 1970-01-01
      • 2017-12-08
      • 2016-11-22
      • 1970-01-01
      • 2021-02-24
      • 1970-01-01
      相关资源
      最近更新 更多