在角度項目中啓動npm後出現此錯誤。如何在angular2中使用sweetalert2
app/app.component.ts(12,7): error TS2304: Cannot find name 'swal'. app/app.component.ts(21,7): error TS2304: Cannot find name 'swal'.
我創建了一個角度項目。裏面app.component.ts我加甜,報警代碼
export class AppComponent {
deleteRow() {
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then(function() {
swal(
'Deleted!',
'Your file has been deleted.',
'success'
);
})
}
}
我做
npm install sweetalert2 --save
也加入index.html的路徑由@yurzui給出
<script src="node_modules/sweetalert2/dist/sweetalert2.min.js"></script>
<link rel="stylesheet" type="text/css" href="node_modules/sweetalert2/dist/sweetalert2.css">
嘗試'聲明VAR SwaI位:任意;'或安裝聲明文件https://github.com/ DefinitelyTyped/DefinitelyTyped/blob/master/sweetalert/sweetalert.d.ts – yurzui
@yurzui感謝您的快速回復。我需要在哪裏添加這個文件? –
其實如果評論swal代碼和做npm安裝和後,如果我取消註釋swal代碼它的作品。 –