Я пытаюсь использовать http с Angular2. Вот мой код:Получить сообщение об ошибке Angular2 http в Es5
var _domain = 'http://localhost:3000/';
app.Applications = ng.core.Injectable().Class({
constructor: [ng.http.Http, function(http) {
this.http = http;
this.emailExistUrl = _domain + 'api/applications/email';
}],
doesEmailExist: function(email) {
var data = { email: email };
return this.http.post(this.emailExistUrl, data)
.toPromise()
.then(function(response) { response.json().data; })
.catch(this.handleError);
}
});
Основной компонент:
app.AppComponent = ng.core
.Component({
selector: 'register-form',
templateUrl: 'src/register/app.component.html',
providers: [app.Applications]
})
.Class({
constructor: [ng.core.ElementRef, app.Applications, function(ref, Applications) {
this.programs = JSON.parse(ref.nativeElement.getAttribute('programs'));
this.applications = Applications;
}],
doesEmailExist: function(email) {
return this.applications.doesEmailExist(email);
}
});
Вот main.js файл:
document.addEventListener('DOMContentLoaded', function() {
ng.platformBrowserDynamic.bootstrap(app.AppComponent, [
ng.forms.disableDeprecatedForms(),
ng.forms.provideForms(),
ng.http.HTTP_PROVIDERS,
]);
});
Когда doesEmailExist называется я получаю сообщение об ошибке из модуля HTTP :
vendor-client.min.js: 55470 ТипError: Не удается прочитать свойство 'platform_browser_private 'of undefined
Любые идеи?
FIXED: Http был до платформы-браузера в списке тегов скриптов. :/
<script src="https://npmcdn.com/@angular/http/bundles/http.umd.js"></script>
<script src="https://npmcdn.com/@angular/platform-browser/bundles/platform-browser.umd.js"></script>
<script src="https://npmcdn.com/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js"></script>
Обратное лучше :)
по-прежнему та же ошибка – user2705463
Извините, я смутил метод 'isEmailExist' с' emailExistUrl'. Где вы называете метод? – robisim74
От основного компонента. Служба приложений вводится в основной компонент. Он также имеет метод doEmailExist с: return this.applications.doesEmailExist (email); – user2705463