ThomasDuc ThomasDuc - 1 month ago 32
TypeScript Question

Cannot find name 'swal' ng2

I am using angular 2 with typescript 1.6 and when i compile the code i get this errors:


Cannot find name 'swal' ng2


This is the code:

 

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


Answer

Thank everyone first, i have just found solution on this link ionic2 TypeScript shows error: Cannot find name 'google' and '$', but google map and jquery still works

The easy fix is to add variable declarations on top of your file:



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

    declare let swal: any;


Comments