Angular Material Components in Ng-Sweet-Alert-2

最后都变了- 提交于 2019-12-08 06:58:38

问题


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 });
}

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?


回答1:


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);

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);


来源:https://stackoverflow.com/questions/34526016/angular-material-components-in-ng-sweet-alert-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!