0

I suspect this is a very simple question that I'm just struggling with as I'm pretty new to this. I appreciate any help, or just pointing in the right direction.

I have a button that upon clicking it, I want it to execute multiple functions that I have written in the same ts file. The onClick() is working as if I put console.log statements in it, those will run. However calls to other functions do not.

Relevant code below should clarify my question:

HTML:

<button type="submit"
        class="btn btn-success"
        (click)="onSaveChanges()">
  Save Changes
</button>

TS:

  private populateToDeleteArray = () => {
    this.groupsToDelete = this.originalUserAssociatedGroups
      .filter(i1 => !this.pickListUserAssociatedGroups
        .some(i2 => i1.id === i2.id));
  }
  private populateToPostArray = () => {
    this.groupsToPost = this.pickListUserAssociatedGroups
      .filter(i1 => !this.originalUserAssociatedGroups
        .some(i2 => i1.id === i2.id));
  }

The other two functions are defined in a similar manner... Then the onClick():

  onSaveChanges = () => {
    console.log('Huh?');
    this.populateToDeleteArray();
    this.populateToPostArray();
    this.sendDeleteRequests();
    this.sendPostRequests();
  }

And as said above, the console.log runs, but the other functions are not called. I'm rather confused.

Thank you in advance!

6
  • Are you sure there's no error in the console? Commented Jul 17, 2020 at 16:36
  • Place console.lot statements in the other methods to confirm if they are invoked or not. Commented Jul 17, 2020 at 16:37
  • can you change your button type submit to button and try again ? Commented Jul 17, 2020 at 16:38
  • Certain. That's what is confusing me the most. It's as if the program isn't even recognizing the other lines. There is just no response at all for anything except the console.log's. Commented Jul 17, 2020 at 16:39
  • 1
    Nicholas K. Ok, I've done that... it appears that I was confused about the wrong thing. When I place console.log statements in each of the functions and click the button, those console.log's appear. That means the functions are being called, and there is just an issue with the functions themselves. That's an entirely different problem. Thanks very much. Commented Jul 17, 2020 at 16:43

1 Answer 1

1

Could you please try this:-

in HTML

<button type="submit"
        class="btn btn-success"
        (click)="onSaveChanges()">
  Save Changes
</button>

in TS

  populateToDeleteArray(){
    this.groupsToDelete = this.originalUserAssociatedGroups
      .filter(i1 => !this.pickListUserAssociatedGroups
        .some(i2 => i1.id === i2.id));
       console.log('working 1st');
  }
  populateToPostArray(){
    this.groupsToPost = this.pickListUserAssociatedGroups
      .filter(i1 => !this.originalUserAssociatedGroups
        .some(i2 => i1.id === i2.id));
        console.log('working 2nd');
  }

  onSaveChange() {
    console.log('Huh?');
    this.populateToDeleteArray();
    this.populateToPostArray();
  }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much for the response. This is the same suggestion as Nicholas K had made above. It showed me that I was wrong, and in fact, the functions are being called. The problem is with those individual functions. I'm not sure of the etiquette here. Given that my question was confused and it is thus not very likely to help others, what should I do next? Just leave the question as is? Should I "vote to delete" to prevent others from answering?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.