Ng-Sweet-Alert-2 中的 Angular Material 组件 [英] Angular Material Components in Ng-Sweet-Alert-2

查看:19
本文介绍了Ng-Sweet-Alert-2 中的 Angular Material 组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 ng-sweet-alert 对话框中放置一个包含 Angular 材质输入组件(包含在我的项目中)的 HTML 代码:

I try to put an HTML code including Angular material input component (which is included in my project) in ng-sweet-alert dialog:

 var strVar="";
  strVar += "<div> <md-input-container style=\"padding-left:0px;\" flex=\"\">   

<label>Titel<\/label> <input ng-model=\"WBQuery.Titel\"> 
  <\/md-input-container> <\/div>";

swal({   
    title: 'HTML example',   
    html: strVar });
}

但显示的只是 HTML 的标准输入字段.是否有任何(黑客)方法可以在该对话框中使用角材料组件?

But what is shown is just the standard input field of HTML. Is there any (hacking) way to use angular material components in that dialog?

推荐答案

我还没试过,但你可以试试这个.调用 swal 函数后,请尝试以下操作:

I've not tried it but you can try this. After you have invoked the swal function, try the following:

(假设您是在指令或控制器中执行此操作)

(Assuming you are doing it in a directive or a controller)

var element = angular.element(document.querySelector(".sweet-alert"));
$compile(element.contents())($scope);

如果这不起作用,请尝试将上述代码放在 $timeout 服务中:

If that doesn't work, try to put the above code in a $timeout service:

$timeout(function() {
    var element = angular.element(document.querySelector(".sweet-alert"));
    $compile(element.contents())($scope);
}, 2000);

这篇关于Ng-Sweet-Alert-2 中的 Angular Material 组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆