异常:"click" 计算期间的错误仅在第一次点击后发生
EXCEPTION: Error during evaluation of "click" occurs only after the 1st click
我正在做 ionic2 http post 服务。
使用“(click)”功能,我的 http post 将被调用,一切都在第一次运行。当我 第二次 按下按钮时,奇怪的事情发生了。
弹出此错误:
所以我试着玩弄它。我在调用点击函数的方法中添加了 console.log。
第 3 次 按钮被按下等等,没有错误消息,我的 http post 也没有工作。只有我的方法内部的 console.log 在单击时打印。
这是我的 html:
<button class="button button-block" (click)="loginSuccess()" style="width:70%;">
<strong>Log In</strong>
</button>
这是我的js:
loginSuccess() {
console.log("Invoked Meod!");
this.httpService.loginService("VariablesToThrowOver").subscribe(
data => {this.httpService = data.results; console.log(data);},
err => console.log(err),
() => console.log('Invoked Login Service Complete'));
}
这是我的服务 js:
loginService(httpService) {
console.log("Service Function Variable: "+httpService);
var body = 'username=' + "admin" + '&password=' + "admin" +'';
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
var url = 'http://localhost/webservice/userrWS.asmx/login';
return this.http.post(url,body, {headers: headers}).map(res => res.json());
}
我猜这与订阅服务有关。如果是这种情况,我如何关闭订阅以再次允许相同的请求?
你的代码有点奇怪,特别是这一行:
this.httpService.loginService("VariablesToThrowOver").subscribe(
data => {this.httpService = data.results; console.log(data);}, // <------
实际上,您尝试将接收到的数据设置到您用来执行登录处理的服务变量本身。我很确定对象 data.results
中没有 loginService
方法。所以第二次点击的时候会报错...
我会选择另一个(和不同的)组件 属性 来存储此数据并将其显示到视图中。像这样:
this.httpService.loginService("VariablesToThrowOver").subscribe(
data => {
this.results = data.results; // <------
console.log(data);
},
我正在做 ionic2 http post 服务。
使用“(click)”功能,我的 http post 将被调用,一切都在第一次运行。当我 第二次 按下按钮时,奇怪的事情发生了。
弹出此错误:
所以我试着玩弄它。我在调用点击函数的方法中添加了 console.log。
第 3 次 按钮被按下等等,没有错误消息,我的 http post 也没有工作。只有我的方法内部的 console.log 在单击时打印。
这是我的 html:
<button class="button button-block" (click)="loginSuccess()" style="width:70%;">
<strong>Log In</strong>
</button>
这是我的js:
loginSuccess() {
console.log("Invoked Meod!");
this.httpService.loginService("VariablesToThrowOver").subscribe(
data => {this.httpService = data.results; console.log(data);},
err => console.log(err),
() => console.log('Invoked Login Service Complete'));
}
这是我的服务 js:
loginService(httpService) {
console.log("Service Function Variable: "+httpService);
var body = 'username=' + "admin" + '&password=' + "admin" +'';
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
var url = 'http://localhost/webservice/userrWS.asmx/login';
return this.http.post(url,body, {headers: headers}).map(res => res.json());
}
我猜这与订阅服务有关。如果是这种情况,我如何关闭订阅以再次允许相同的请求?
你的代码有点奇怪,特别是这一行:
this.httpService.loginService("VariablesToThrowOver").subscribe(
data => {this.httpService = data.results; console.log(data);}, // <------
实际上,您尝试将接收到的数据设置到您用来执行登录处理的服务变量本身。我很确定对象 data.results
中没有 loginService
方法。所以第二次点击的时候会报错...
我会选择另一个(和不同的)组件 属性 来存储此数据并将其显示到视图中。像这样:
this.httpService.loginService("VariablesToThrowOver").subscribe(
data => {
this.results = data.results; // <------
console.log(data);
},