0
関数内でajaxが機能しないようですが、ここで何が間違っていますか?関数内でIonic HTTPが機能しない
import { FormControl } from '@angular/forms';
import { Http } from '@angular/http';
export class EmailValidator {
static checkEmail (control: FormControl): any {
var $http = new Http;
return new Promise(resolve => {
var lowercaseValue = control.value.toLowerCase();
if(lowercaseValue.indexOf('@') <= -1 || lowercaseValue.indexOf('.') <= -1) {
resolve({
"invalid email": true
});
} else {
$http({
method: 'GET',
url: '{URL}'+lowercaseValue
}).then(function successCallback(response) {
if(response.error == true) {
resolve(response);
} else {
resolve(null);
}
}, function errorCallback(response) {
resolve({
"invalid email": true
});
});
}
});
}
}
私が手にエラーがある:コンストラクタメソッドに引数としてそれを追加してみてください
constructor(_backend: ConnectionBackend, _defaultOptions: RequestOptions)
https://angular.io/api/http/Http
:
それでもコンストラクタクラスとなし、外出先:http://cdn.microthosting.com/imgs/
また、ブートストラップコードに
HttpModule
をインポートするために、このようなものが必要Screenshot_at_2017-06-15_12-02-58.png http://cdn.microthosting.com/imgs/Screenshot_at_2017-06-15_12-03-13.png – jfreak53これは、クラスが正しく設定されていないことを意味します。あなたのクラスに 'Http'クラスを注入する前に、真実である必要があるいくつかのことがあります。このチュートリアルを確認してください:https://angular.io/guide/http –
この記事では、「HttpModule」の詳細について説明します:https://medium.com/google-developer-experts/angular-2-introduction-to-new -http-module-1278499db2a0 –