[英]Empty white screen while trying to compile and run ionic2
I am trying to create a simple HTTP post service for my login page. 我正在尝试为我的登录页面创建一个简单的HTTP发布服务。
For some weird reasons, i encountered errors in my app.bundle.js: 由于一些奇怪的原因,我在我的app.bundle.js中遇到了错误:
TypeError: Cannot read property 'toString' of undefined TypeError:无法读取未定义的属性“ toString”
Uncaught TypeError: Cannot read property 'getOptional' of undefined 未捕获的TypeError:无法读取未定义的属性“ getOptional”
Using ionic2 tutorial sample project, I have done the following: 使用ionic2教程样本项目,我已经完成了以下工作:
In my app.js (so my service would be accessible globally) 在我的app.js中(这样我的服务将可以全局访问)
import {HttpService} from './services/httpService';
@App({
templateUrl: 'build/app.html',
config: {} ,// http://ionicframework.com/docs/v2/api/config/Config/
providers: [HttpService]
})
and set the rootPage to my login page 并将rootPage设置为我的登录页面
this.rootPage = LoginPage;
In my log-in.html 在我的log-in.html中
<button class="button button-block" (click)="loginSuccess()" style="width:70%;">
<strong>Log In</strong>
</button>
In my log-in.js 在我的login.js中
import {App, Page, Platform, IonicApp, NavParams, NavController} from 'ionic-angular';
import {HttpService} from '../../services/httpService';
@Page({
templateUrl: 'build/pages/log-in/log-in.html'
})
export class LoginPage {
constructor(nav,app,httpService) {
this.nav = nav;
this.app = app;
this.httpService = httpService;
}
loginSuccess() {
console.log("Invoked Method!");
this.httpService.loginService(event.target.value).subscribe(
data => {this.httpService = data.results; console.log(data);},
err => this.logError(err),
() => console.log('Invoked Login Service Complete')
);
}
}
httpService.JS httpService.JS
import { Inject } from 'angular2/core';
import { Http } from 'angular2/http';
import 'rxjs/add/operator/map';
export class httpService {
static get parameters() {
return [[Http]];
}
constructor(http) {
this.http = http
}
loginService(httpService) {
console.log("Service Function Variable: "+httpService);
// var body = "username=" + username + "&password=" + password+" &ipAddress="+ip;
var body = "username=" + "admin" + "&password=" + "admin" +" &ipAddress="+"127.0.0.1";
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
var url = 'http://localhost/WS/Login.asmx/Login';
return this.http.post(url,body, {headers: headers}).map(res => res.json());
}
}
As you can see, I'm just trying to get my services up. 如您所见,我只是在尝试提高服务水平。 All I am presented is a blank white screen and errors from app.bundle.js (which is generated at compile time), yet I do not have any compile errors while compiling. 我所看到的只是空白的屏幕和来自app.bundle.js的错误(在编译时生成),但是编译时我没有任何编译错误。
And the app.bundle.js code which have errors are: 而有错误的app.bundle.js代码是:
exports.isJsObject = isJsObject;
function print(obj) {
console.log(obj);
}
and 和
var inits = injector.getOptional(application_tokens_1.APP_INITIALIZER);
which I have no idea as this is generated automatically. 我不知道这是自动生成的。 I apologise for the code dump(I have tried to remove unnecessary stuff) as I do not know which part of it went wrong. 我为代码转储道歉(我已尝试删除不必要的内容),因为我不知道它的哪一部分出错了。
My ionic version is : 2.0.0-beta.25 if that helps. 我的离子版本是:2.0.0-beta.25如果有帮助。
Any help would be deeply appreciated. 任何帮助将不胜感激。
Had a look at your code. 看了一下你的代码。 I could see that you have used Headers but haven't imported them in your code. 我可以看到您使用了Header,但尚未将其导入代码中。 In the httpService.js file modify the import statement as shown below. 在httpService.js文件中,修改import语句,如下所示。
import { Http, Headers } from 'angular2/http';
app.bundle.js is simply a bundle of modules generated by webpack which is popular module loader used by Ionic. app.bundle.js只是由webpack生成的模块的捆绑包,webpack是Ionic使用的流行模块加载器。
PS: If you are trying to implement an authentication system in your Ionic 2 application, I recommend you to have a look here . PS:如果您尝试在Ionic 2应用程序中实施身份验证系统,建议您在此处查看 。
Hope this helped you. 希望这对您有所帮助。 Thanks. 谢谢。
I don't see the decorator @Injectable on your service... 我在您的服务上看不到装饰器@Injectable ...
export class httpService { 导出类httpService {
should be (i think, I´m using v24, maybe in v25 is different?) 应该是(我认为我正在使用v24,也许在v25中有所不同?)
import {Injectable, Inject} from "angular2/core"; 从“ angular2 / core”导入{Injectable,Inject};
@Injectable export class httpService { @Injectable导出类httpService {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.