EXCEPTION: Error during evaluation of “click” occurs only after the 1st click

I’m doing a ionic2 http post service.

Using the “(click)” function, my http post will be invoked and everything works the first time. The strange thing happens when I press the button the 2nd time.

This error pops up:

Error Message

So i tried to play around with it. I have added a console.log inside my method which the click function is invoked.

On the 3rd time the button is pressed and so on, there is no error message , neither is my http post is working. Only my console.log inside the method are printing upon click.

Console log

This is my html:

<button  class="button button-block" (click)="loginSuccess()" style="width:70%;">
 <strong>Log In</strong>

This is my js:

loginSuccess() {
    console.log("Invoked Meod!");
    data => {this.httpService = data.results; console.log(data);},
    err => console.log(err),
    () => console.log('Invoked Login Service Complete'));

And this is my service 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());

I’m guessing it has something to do with the subscribe service. If that is the case, how do i close the subscribe to allow for a identical request again?

Leave a Reply

1 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
newest oldest most voted
Notify of

Your code is a bit strange, specially at this line: this.httpService.loginService("VariablesToThrowOver").subscribe( data => {this.httpService = data.results; console.log(data);}, // <------ In fact, you try to set the received data into the service variable itself you use to execute the login processing. I’m pretty sure that there is no loginService method into the object data.results. So when you click a second time, you will have an error… I would choose another (and distinct) property of your component to store this data and display it into the view. Something like this: this.httpService.loginService("VariablesToThrowOver").subscribe( data => { this.results = data.results; // <------ console.log(data); },