ThomasDuc ThomasDuc - 1 year ago 164
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';

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

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
Answer Source

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;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download