找不到名字' swal' NG2

时间:2016-10-07 12:44:29

标签: angular typescript sweetalert

我使用的是带有typescript 1.6的angular 2,当我编译代码时,我得到了这个错误:

  

找不到名字' swal' NG2

这是代码:

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

@Component({ selector: 'message-list', styles: [], template: require('./message-list.component.html') })

export class MessagesComponent { ngOnInit(): void { swal({ title: "Error!", text: "Here's my error message!", type: "error", confirmButtonText: "Cool" }); } }

1 个答案:

答案 0 :(得分:3)

首先感谢大家,我刚刚在这个链接上找到了解决方案 ionic2 TypeScript shows error: Cannot find name 'google' and '$', but google map and jquery still works

简单的解决方法是在文件顶部添加变量声明:



    import {...} from '...';

    declare let swal: any;