【发布时间】:2016-04-18 07:01:15
【问题描述】:
我正在做一个 ionic2 http post 服务。
使用“(点击)”功能,我的 http 帖子将被调用,一切都在第一次运行。当我第二次按下按钮时,奇怪的事情发生了。
弹出这个错误:
所以我试着玩弄它。我在调用 click 函数的方法中添加了一个 console.log。
在第三次按下按钮等等,没有错误消息,我的 http 帖子也没有工作。只有我在方法中的 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());
}
我猜这与订阅服务有关。如果是这种情况,我如何关闭订阅以再次允许相同的请求?
【问题讨论】:
-
我在您的问题中看不到任何
(click)="xxx",也看不到有关单击时执行的功能的任何其他信息。 -
@GünterZöchbauer 您好,我已编辑!谢谢!
标签: javascript ionic-framework angular ionic2