使用AngularJS 2和模板的Sweet Alert

稻田

当不使用Angualr模板时,我有一个运行良好的小型应用程序。但是,我现在需要将代码导出到其中。单击按钮时应调用Sweet Alert。因此,当通过模板调用按钮时,会弹出甜蜜警报,但什么也没有发生。我保证这与均匀绑定有关,因为在DOM初始化后应用程序加载了代码。

//app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  template: `
    <form>
     <button type="button" class="ticket_button">Book</button>
    </form>
    `
})
export class AppComponent {
//some app logic here
}


//index.html
//i have not included the normal header stuff here, however the my-app class shows the button 

<html<body>
    <my-app class="main_ticket">Loading...</my-app>
</body></html>

// I have tried to use event binding from Jquery $('.main_ticket').on('change', '.ticket_button', function() {//logic here}, but it also didn't work 

<script>
 //Sweet Alert call
document.querySelector('button').onclick = function(){
  swal("Here's a message!");
};
</script>
i

您必须使用救生圈挂钩才能使其正常工作:

export class AppComponent implements ngAfterViewInit{
//some app logic here

     ngAfterViewInit(){
       document.querySelector('button').onclick = function(){
          swal("Here's a message!");
       };
     }

}

或者更好地使用angular2的标准事件

@Component({
  selector: 'my-app',
  template: `
    <form>
     <button type="button" (click)="popAlert();" class="ticket_button">Book</button>
    </form>
    `
})

现在在班级:

export class AppComponent {
//some app logic here
    popAlert(){
      swal("Here's a message!");
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用Sweet-alert消息和Laravel 5.2删除类别

来自分类Dev

使用Sweet-alert消息和Laravel 5.2删除类别

来自分类Dev

JSF Sweet Alert 使用 FacesMessages

来自分类Dev

Sweet Alert 2 jQuery 文件使用 php 上传

来自分类Dev

Sweet alert 2. 重置防止默认

来自分类Dev

Sweet Alert 2 - “confirmButtonText”按钮中的链接

来自分类Dev

android如何在Eclipse上使用sweet-alert-dialog

来自分类Dev

在 Vue js 中使用 Sweet alert 删除确认

来自分类Dev

Sweet Alert HTML选项

来自分类Dev

alert()和alert``之间的区别

来自分类Dev

Bootstrap Modal内部的Sweet Alert

来自分类Dev

删除确认 HREF Sweet Alert

来自分类Dev

PHP onclick 确认到 Sweet Alert 2 确认

来自分类Dev

如何使用Blazor使用alert(),confirm()和hint()函数?

来自分类Dev

Uncaught TypeError:无法使用Sweet Alert读取未定义的属性'then'

来自分类Dev

使用showLoaderOnConfirm时在Sweet Alert中禁用输入文本框

来自分类Dev

使用alert()显示消息

来自分类Dev

在Alert中使用getElementById

来自分类Dev

Laravel 5.2-Sweet Alert确认框

来自分类Dev

Sweet Alert后的文件上传窗口

来自分类Dev

基于 id 的 Sweet Alert 和 ajax 调用在 php while 循环中

来自分类Dev

Jade模板和angularjs的实际使用

来自分类Dev

在AngularJS中使用模板和过滤

来自分类Dev

使用angularjs和rails加载html模板

来自分类Dev

alert(“ Hi!”)和function(){alert(“ Hi!”)}之间的区别

来自分类Dev

JavaScript中“ alert(a)”和“ alert(a); var a = 1;”之间的区别?

来自分类Dev

如何使Alert.alert消息能够复制和粘贴?

来自分类Dev

Java Selenium-无法同时使用Chrome和firefox到达Alert

来自分类Dev

使用Karma,Jasmine和ngHtml2JsPreprocessor的AngularJS测试指令:未加载模板

Related 相关文章

  1. 1

    使用Sweet-alert消息和Laravel 5.2删除类别

  2. 2

    使用Sweet-alert消息和Laravel 5.2删除类别

  3. 3

    JSF Sweet Alert 使用 FacesMessages

  4. 4

    Sweet Alert 2 jQuery 文件使用 php 上传

  5. 5

    Sweet alert 2. 重置防止默认

  6. 6

    Sweet Alert 2 - “confirmButtonText”按钮中的链接

  7. 7

    android如何在Eclipse上使用sweet-alert-dialog

  8. 8

    在 Vue js 中使用 Sweet alert 删除确认

  9. 9

    Sweet Alert HTML选项

  10. 10

    alert()和alert``之间的区别

  11. 11

    Bootstrap Modal内部的Sweet Alert

  12. 12

    删除确认 HREF Sweet Alert

  13. 13

    PHP onclick 确认到 Sweet Alert 2 确认

  14. 14

    如何使用Blazor使用alert(),confirm()和hint()函数?

  15. 15

    Uncaught TypeError:无法使用Sweet Alert读取未定义的属性'then'

  16. 16

    使用showLoaderOnConfirm时在Sweet Alert中禁用输入文本框

  17. 17

    使用alert()显示消息

  18. 18

    在Alert中使用getElementById

  19. 19

    Laravel 5.2-Sweet Alert确认框

  20. 20

    Sweet Alert后的文件上传窗口

  21. 21

    基于 id 的 Sweet Alert 和 ajax 调用在 php while 循环中

  22. 22

    Jade模板和angularjs的实际使用

  23. 23

    在AngularJS中使用模板和过滤

  24. 24

    使用angularjs和rails加载html模板

  25. 25

    alert(“ Hi!”)和function(){alert(“ Hi!”)}之间的区别

  26. 26

    JavaScript中“ alert(a)”和“ alert(a); var a = 1;”之间的区别?

  27. 27

    如何使Alert.alert消息能够复制和粘贴?

  28. 28

    Java Selenium-无法同时使用Chrome和firefox到达Alert

  29. 29

    使用Karma,Jasmine和ngHtml2JsPreprocessor的AngularJS测试指令:未加载模板

热门标签

归档