I am trying to make a request AJAX
from Ionic
, I have this html:
<ion-header>
<ion-navbar>
<ion-title>
Prueba AJAX
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<div center text-center>
<button ion-button (click)="traerInfo()">
Informacion ajax
</button>
</div>
</ion-content>
And I have the following .ts
:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AlertController } from 'ionic-angular';
@Component({
selector: 'page-prueba',
templateUrl: 'prueba.html'
})
export class PruebaPage {
constructor(public navCtrl: NavController, public alerCtrl: AlertController) {
}
traerInfo() {
$http.get("https://www.w3schools.com/xml/ajax_info.txt")
.then(function(response) {
let alert = this.alerCtrl.create({
title: 'Informacion obtenida!',
message: response,
buttons: ['Ok']
});
alert.present()
});
}
}
I'm getting an error that the variable $http
is not defined. But I already tried including it in constructor
:
constructor(public navCtrl: NavController, public alerCtrl: AlertController, public http: $http)
Or even doing the same thing importing everything as explained here:
import { Http, Response } from '@angular/http';
And doing in the constructor:
constructor(public navCtrl: NavController, public alerCtrl: AlertController, public http: Http)
But it did not work either ...
My options ran out, thank you very much!